xuchaobei / react-book Goto Github PK
View Code? Open in Web Editor NEW《React进阶之路》示例代码
《React进阶之路》示例代码
post的author老是为null,然后疯狂报错
production环境下,报找不到store,
// redux/index.js finalCreateStore = applyMiddleware(thunk)(createStore);
是否需要改成
// redux/index finalCreateStore = compose(applyMiddleware(thunk))(createStore);
chapter07 bbs-router的可以登录的帐号密码是多少?
试了tom,jack都不行
function withPersistentData = (key) => (WrappedComponent) => { return class extends Component {
///...
后端的服务能提供一下么
const currentUser = filterUsers.length > 0 ? filterUsers[0] : null;
这个例子中,是否是应该要初始化
currentUserId 为 0
然后设置
const currentUser = filterUsers.length > 0 ? filterUsers[currentUserId] : null;
因为在 handleSetCurrentUser 的时候,只是 更新了 currentUserId 的值?
看了您的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,请问我的想法是不是也不太好,或者您有什么想法可以提示给我的吗?多谢您查看我的问题,期待您的回答
componentWillMount() { let data = localStorage.getItem('data'); if(data) { this.setState({ data, }) } }
书中以上的这段代码为什么会选择写在componentWillMount
中,而不是componentDidMount
中呢?
4、5、6章没有代码吗,没找到呢
有人没有登录就发了帖子,导致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
}
}
this.setState((preState, props) => ({counter: preState.quantity + 1}))
?A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.