Last active
February 10, 2017 23:11
-
-
Save asfktz/f14a274d6072b4beaf496df858d24998 to your computer and use it in GitHub Desktop.
react-redux-form nested reducer issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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')); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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