我试图采用在'容器组件'(又名智能组件)&中执行所有操作,然后只是将数据传递到“表示组件”的理念。验证React-Redux中“容器组件”中的触发事件
我被困在这一点,我需要验证用户操作(事件触发),然后我将动作发送到Reducer
。我想这样做的方法是通过在'mapDispatchToProps'内的函数中验证事件。
的代码看起来是这样的:
const mapStateToProps = ({ oneState, twoState }) => {
return({
oneState : oneState,
twoState : twoState
});
};
const mapDispatchToProps = (dispatch) => {
return({
dispatchOneAction :() => {
// do the validation here. The validation requires access to
// the 'oneState' obj above in the 'mapStateToProps'
}
});
};
const C_Element = connect(mapStateToProps, mapDispatchToProps)(Ele);
我的问题是,这可能吗?或者我必须在presentation component
下游执行验证,然后调用'dispatchOneAction'函数?
为什么不直接定义在验证容器组件的功能,并把它作为一个道具呈现组件? – kinakuta
感谢@kinakuta这是一个非常好的建议 – Kayote