How to use redux-form with redux-persist?

Viewed 292

My code works absolutely fine. I need some help in modifying my code such that it should store data persistently (after refresh the form should be filled with same data the user entered). The sections to be modified in App.js is dispatcher and store.js. Any help or logical suggestions are most welcome. Thanks in advance. Here is my App.js

const Form = (props) => {
  const { handleSubmit } = props;
  const onSubmit = (values) => console.log(values);
  const renderInput = ({ input: { onChange, ...input }, ...rest}) => {
    return <TextInput style={styles.input} onChangeText={onChange} {...input} {...rest} />
  };

  return (
    <View style={styles.root}>
      <Field
        name={'email'}
        props={{
          placeholder: 'Email'
        }}
        component={renderInput}
      />
      <Field
        name={'password'}
        props={{
          placeholder: 'Password',
          secureTextEntry: true
        }}
        component={renderInput}
      />
      <Button title={'Submit'} onPress={handleSubmit(onSubmit)} />
    </View>
  );
};

const mapStateToProps = state => {
  return {
    email: state.email,
    password: state.password
  }
};

const mapDispatchToProps = (dispatch) => {
    return {
        fetchUserEmail: () => dispatch(email()),
        fetchPassword: () => dispatch(password()),
   };
};
export default reduxForm({form: 'test-form', destroyOnUnmount: false})(Form);

And my store.js

import {combineReducers, createStore, applyMiddleware} from 'redux';
import {reducer as formReducer} from 'redux-form';
import AsyncStorage from '@react-native-community/async-storage';
import { createLogger } from 'redux-logger';
import { persistStore, persistReducer } from 'redux-persist';

const rootReducer = combineReducers({
  form: formReducer,
  
});

const store = createStore(rootReducer);

export default store;
0 Answers
Related