当有人使用react-redux的connect函数时,是否有人知道如何使用React.memo包装React组件?
let Button = (props: Props) => ( <button onClick={props.click}>{props.value}</button> ); Button = connect( mapStateToProps,mapDispatchToProps )(Button);
我试过了:
let Button = React.memo((props: Props) => ( <button onClick={props.click}>{props.value}</button> )); Button = connect( mapStateToProps,mapDispatchToProps )(Button);
但是,connect返回的函数需要传递一个组件,因此它出错:
Uncaught Error: You must pass a component to the function returned by
connect. Instead received {“compare”:null}
解决方法
同样的问题在这里通过将react-redux升级到版本5.1.0来修复.