你需要使用一个formValueSelector http://redux-form.com/6.5.0/docs/api/FormValueSelector.md/
const selector = formValueSelector('formName');
function mapStateToProps(state, props) {
const isChecked = selector(state, 'checkboxField');
return { isChecked };
}
connect
using mapStateToProps
渲染方法将如下所示。
render() {
return (
{ this.props.isChecked && (
<div>
this only shows up if the checkboxField Field is checked
</div>
) }
);
}
edit:
看起来你正在使用reselect
- 我从来没有用过createStructuredSelector
我并不 100% 理解文档,但可能的解决方案可能是:
const mMapStateToProps = createStructuredSelector({
request: selectRequestForm(),
user: selectUser()
});
const mapStateToProps = (state, props) => {
return {
isChecked: selector(state, 'checkboxField'),
... mMapStateToProps(state, props) // not sure if createStructuredSelector accepts a props param
}
};
这将组成两者。我想你也可以使用createSelector
with mMapStateToProps
和mapStateToProps
我原来发帖...