Skip to content

Instantly share code, notes, and snippets.

@asfktz
Last active February 10, 2017 23:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save asfktz/f14a274d6072b4beaf496df858d24998 to your computer and use it in GitHub Desktop.
Save asfktz/f14a274d6072b4beaf496df858d24998 to your computer and use it in GitHub Desktop.
react-redux-form nested reducer issue
import React from 'react';
import ReactDOM from 'react-dom';
import { Provider } from 'react-redux';
import store from './store.js';
import UserForm from './UserForm.js';
class App extends React.Component {
render() {
return (
<Provider store={ store }>
<UserForm />
</Provider>
);
}
}
ReactDOM.render(<App />, document.getElementById('root'));
import { createStore, combineReducers } from 'redux';
import { combineForms } from 'react-redux-form';
const initialUserState = {
firstName: '',
lastName: ''
};
const reducer = combineReducers({
forms: combineForms({
user: initialUserState,
})
})
const store = createStore(reducer);
export default store;
import React from 'react';
import { Control, Form } from 'react-redux-form';
class UserForm extends React.Component {
render() {
return (
<Form model="forms.user"
onSubmit={(user) =>
console.log('-->', user)
}>
<label>First name:</label>
<Control.text model=".firstName" />
<label>Last name:</label>
<Control.text model=".lastName" />
</Form>
);
}
}
export default UserForm;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment