简体   繁体   English

我可以像[v5]一样将redux-form [v6]连接到其他状态吗?

[英]Can i connect redux-form [v6] to other state, like in [v5]?

Can i configure mapStateToProps and other react-redux parameters in redux-form v6 . 我可以在redux-form v6配置mapStateToProps和其他react-redux参数mapStateToProps

Like this in redux-form v5 ~> http://i.stack.imgur.com/nSZKM.jpg redux-form v5就像这样〜> http://i.stack.imgur.com/nSZKM.jpg

 reduxForm(config:Object, mapStateToProps?, mapDispatchToProps?, mergeProps?, options?) 

Creates a decorator with which you use redux-form to connect your form component to Redux. 创建一个装饰器,您可以使用该装饰器使用redux-form将表单组件连接到Redux。 It takes a config parameter and then optionally mapStateToProps, mapDispatchToProps, mergeProps and options parameters which correspond exactly to the parameters taken by react-redux's connect() function, allowing you to connect your form component to other state in Redux. 它需要一个config参数,然后可选地包含mapStateToProps,mapDispatchToProps,mergeProps和options参数,这些参数与react-redux的connect()函数所采用的参数完全对应,从而允许您将表单组件连接到Redux中的其他状态。

.

For example: 例如:

import { reduxForm } from 'redux-form/immutable';

...

export default reduxForm({
  form: 'signUp'
}, state => ({
  lists: state.get('list').toJS()
}));

Yes, you can connect your redux state to your redux-form component in version 6. Here is an example (You have to decorate connect manually now). 是的,您可以将redux状态连接到版本6中的redux-form组件。这是一个示例(您现在必须手动装饰连接)。

import { connect } from 'react-redux';
import { reduxForm } from 'redux-form';
import {
    actionCreatorOne,
    actionCreatorTwo
} from './actionCreators';

class MyForm...

function mapStateToProps(state) {
    return {
        name: state.user.name
    };
}

let mapDispatch = {
    actionCreatorOne,
    actionCreatorTwo
};

MyForm = reduxForm({
    form: 'myForm'
})(MyForm);

export default MyForm = connect(mapStateToProps, mapDispatch)(MyForm);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM