简体   繁体   中英

how to use Redux-form selector : getFormMeta

I have Radio Group component and which internally calls Radio component, I need to access the form meta info in at Radio Group level to be able to check and perform the necessary validation. One thing I came across is getFormMeta selector, but not sure how to use, any working example would be appreciated. Thanks

getFormMeta is a higher order function that takes in the name of the form to connect to and returns a function of type (state) => formMeta .

Since the the props given to a Field's component include the form name, you could then make use of the getFormMeta selector as follows inside your RadioGroup component file:

import { getFormMeta } from 'redux-form';
import { connect } from 'react-redux';

...

class RadioGroup extends Component {
    ...
}

...

const mapStateToProps = (state, ownProps) => {
    const formName = ownProps.meta.form;
    const metaSelector = getFormMeta(formName);

    return {
        formMeta: metaSelector(state)
    };
};

export default connect(mapStateToProps)(RadioGroup);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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