将redux-form formValueSelector移动到HOC

时间:2018-03-28 23:02:27

标签: reactjs redux redux-form

我试图将连接的redux-from选择器移动到处理mapState和mapDispatch的HOC。

目前我的组件看起来像这样......

class MainForm extends React.Component {

render() { ... }

}

let MainReduxForm = reduxForm({
  form: "mainForm", 
})(MainForm);

const selector = formValueSelector('mainForm')
MainReduxForm = connect(state => {
  const isUsed = selector(state, 'isUsed');
  const location = selector(state, 'location');

  return {
    isUsed,
    location,
  };
  },
)(MainReduxForm);

export default MainReduxForm;

和HOC看起来像这样......

const mapState = (state, ownProps) => {
  return {

  };
};



const mapDispatch = (dispatch, ownProps) => {
    return {
      onOrderChange: order => dispatch({type: 'FETCH_ORDER', order: order}),

    }
}

export const MainFormContainer = connect(
  mapState,
  mapDispatch
)(MainReduxForm);

如何将功能的connect / formValueSelector部分移动到HOC?

我不确定它应该在HOC中应该存在多少,但是如果可能的话,我会尝试分离关注点,并且希望将功能块与其他一些在mapDispatch中调用的SAGA片段共存。

0 个答案:

没有答案