Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/arojunior/react-redux-form

React app using redux-form for controlled components
https://github.com/arojunior/react-redux-form

javascript react redux redux-form

Last synced: 16 days ago
JSON representation

React app using redux-form for controlled components

Awesome Lists containing this project

README

        

# react-redux-form

Just a simple example to show how to use controlled components with redux-form.

# modules/index.js
```javascript
/*
* Redux
*/
import {createStore, combineReducers} from 'redux'
import {reducer as formReducer} from 'redux-form'
/*
* Reducers
*/
import Contact from './Contact'
const combineReducer = combineReducers({
form: formReducer,
Contact
})

/*
* Store
*/
export const store = createStore(combineReducer)
```
It´s just redux basic configuration...

# components/Form.js

```javascript
const Form = props => {
const {handleSubmit, pristine, reset, submitting} = props
return (


Name



E-mail



Message




Send
{' '}

Reset



)
}

// Connect Form component and Form reducer
export default reduxForm({
form: 'contactForm'
})(Form)
```

# Container
```javascript
class Contact extends Component {
handleSubmit = (values, dispatch) => {
dispatch(contactSent(values))
dispatch(reset('contactForm'))
}

render() {
const {data} = this.props

return (




Contact




Form data: {data ? JSON.stringify(data) : null}



)
}
}

export default connect(state => state.Contact)(Contact)
```

That's it!

[Redux-form documentation](http://redux-form.com/)

[Article in portuguese](https://medium.com/@arojunior/componentes-controlados-com-react-e-redux-form-e58df1581b62)