0
votes

I want to dispatch a function in redux-forms after clicking loadMore , I have already fetched data from API and I just need to render slice of records at at time.

const mapDispatchToProps = (dispatch) => {
    return {
        loadMore: (value) => {
            dispatch(value);
        },
}}

loadMore = () => {
        this.setState({
            pageNo: this.state.pageNo + 2,
        }, () => {
            setTimeout(() => {
                console.log(this.props);
                this.props.loadMore(this.getData())
            }, 200);
        });
    }

<FieldArray name="getData"
                        component={this.getData}
                    />


getData= ({ fields, meta: { error, submitFailed } }) => {
        let fetchFields = fields.getAll();

        let displayFetchedFields = fetchFields.slice(0, this.state.pageNo);
        if (displayFetchedFields) {
            return displayFetchedFields.map((facility, index) => {
}
}}

After clicking load more Error Comes : get.js:63 Uncaught TypeError: Cannot read property 'fields' of undefined

I think you need to dispatch some action with value not just the value. Also i think you need a return function inside the loadMore component. I am still a beginner in react so giving suggestion on what i understood from the code provided. - Nilesh Jain
Yes exactly, can you help me into this , redux-forms - Madhur
do you have the action and reducer you want to use? - Nilesh Jain
Is the whole code for this component? can you please post the whole code of this component with import statements? I see this.setState which can be used only in class component but i dont see any class component. - Nilesh Jain
Bro I want to cal a function only by clicking on load more, Yes i have reducers and action but i don't thinks it needs to be loaded here, because in that file i am just loading data into state payload - Madhur