我无法弄清楚 Redux 操作是同步的还是异步的。考虑一下:
addBook () => {
console.log( "current books: ",this.props.books );
const book = {
id: 3,
title: "Percy Jackson"
};
this.props.addBook(book); // firing off a new action [ is it synchronous or asynchronous ]
console.log( "updated books: ",this.props.books ); // shouldn't these be new props
}
从上面看,两者current books
和updated books
是相同的,尽管 UI 已更新,我猜来自商店的新道具也通过mapStateToProps
方法传递给该组件。
我错过了什么?