Code Monkey home page Code Monkey logo

react-book's People

Contributors

313183373 avatar xuchaobei avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-book's Issues

TypeError: can't read 'id' of undefind

有人没有登录就发了帖子,导致post的author为null;

// ./src/redux/module/posts.js
const convertPostsToPlain = posts => {
	let postsById = {}
	let postIds = []
	let authorsById = {}
	posts.forEach(item => {

               // Solution for dev
		item = item.author ? item : { ...item, author:{id: 123, username: 'none'}}

		postsById[item.id] = { ...item, author: item.author.id }
		postIds.push(item.id)
		if (!authorsById[item.author.id]) {
			authorsById[item.author.id] = item.author
		}
	})
	return {
		posts: postsById,
		postIds: postIds,
		authors: authorsById
	}
}

第6章

componentWillMount() { let data = localStorage.getItem('data'); if(data) { this.setState({ data, }) } }
书中以上的这段代码为什么会选择写在componentWillMount中,而不是componentDidMount 中呢?

Section 4.3.2 Page 75页 的 currentUser疑问?

const currentUser = filterUsers.length > 0 ? filterUsers[0] : null;

这个例子中,是否是应该要初始化
currentUserId 为 0
然后设置
const currentUser = filterUsers.length > 0 ? filterUsers[currentUserId] : null;

因为在 handleSetCurrentUser 的时候,只是 更新了 currentUserId 的值?

第4章 state 的更新是异步的

  1. 这个购物车数量增加的例子能够模拟吗,理论上是理解的,但是想模拟一下
  2. 一般的计数,万无一失的犯法都是用this.setState((preState, props) => ({counter: preState.quantity + 1}))

mobx实战中api的处理

看了您的mobx实战那一章节,感觉收获很大,现在打算在项目中应用起来,有一个疑问,想要咨询下您的观点
我看store中注入了api的对象,用于在store的action中用api发起请求,对返回数据进行处理存储,现在我也把api注入在了store中,但是我的api中发送请求的方法很多,store只是用到了其中很小一部分,有些api中的请求是在页面通过this.props.store.api.xxx来发起请求,但是这样的话感觉不太合理,一是store中只用了很少一部分api的方法,是否不应该把整个api注入给store,二是页面中为了调用api的方法就必须Injec("store"),这样才能通过this.prop.store.api来调用方法,这也不太合理

我的想法是把api拆开,一部分注入在store中供store的异步action使用,一部分直接在页面中引入,供页面直接发起请求,但是这样又会觉得这一个模块的api被硬生生拆开成两个,而且页面中可以随意引入api,请问我的想法是不是也不太好,或者您有什么想法可以提示给我的吗?多谢您查看我的问题,期待您的回答

production环境下store报错

production环境下,报找不到store,

// redux/index.js finalCreateStore = applyMiddleware(thunk)(createStore);
是否需要改成
// redux/index finalCreateStore = compose(applyMiddleware(thunk))(createStore);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.