- With an attendance of over 250 and a wide range of the latest and greatest from the React world, React Alicante delivered some interesting topics ranging from React Native all the way to GraphQL.
- While I really do see the value in documenting your React components for large scale projects I can also see its value being diminished somewhat for smaller scale projects as the time spent building a system of UI documentation with Storybook while also having to write tests specifically for that…
- Possibly one the most interesting talks at the conference was by Nikolas Burk, His talk (Building a realtime chat app with GraphQL) was extremely engaging.
- A talk by Erik Rasmussen labelled A practical guide to Redux Form was very interesting and made me rethink my current system of form validation using React and Redux.
- Erik is the creator of Redux Form and he outlined how this library provides an easier way to manage the various state changes of a dynamic form.
Last weekend I attended React Alicante. Its the first of its type set in Spain’s southeastern Costa Blanca. It delivered some interesting topics ranging from
- Why build your forms with Redux FormWhen I usually create forms for my React/Redux applications I tend to keep the value of the inputs on the application state, with little to no editing, (because my forms are usually simple), I never stopped to realize what that means.
- It keeps track of all common application form state such as:The fields that are in the form;The values of each field;The focused field;If the field values are valid;The fields that the user have interacted with;If the form is being submitted;If is happening any asynchronous validation.Let’s take a look at a bit of code and see how to do a setup.Here we connect the form component to Redux by decorating it with the high-order component reduxForm.
- It will also hand us the handleSubmit function, which will take care of the submission behavior.The Field component takes our input component as its props and acts as a container, bringing the application state to the input component and binding the event handlers to update the state in store.Look at the InputText component to see the props we receive from the Field.One important point is that it’s still a developer’s responsibility to write the form and inputs components, this way the library does not take the flexibility from you to manage the behaviors of your form the way you want, or even add custom ones.And to finish our integration we add a reducer that will handle the state changes of your form.Simple isn’t it.Just one more point.
- Look that the default value of the input is defined when the high-order component reduxForm is called and comes to the input within the prop input and not from the react’s prop defaultValue, this way we guarantee that our form values are all represented in the application state.In summary, having all your form data in application state gives you control over its behavior and you can easily implement that on a React/Redux application with Redux Form.I have created a repository on GitHub with the implementation above.
When I usually create forms for my React/Redux applications I tend to keep the value of the inputs on the application state, with little to no editing, (because my forms are usually simple), I never…
Continue reading “Why build your forms with Redux Form – DailyJS – Medium”
- Even better, with the latest release candidate (Redux Form 6.0.0rc3) and later, you can upgrade to the latest version of React and not have those pesky errors bring your project to a screeching halt.
- This tutorial is going to help you set up a Redux Form that uses the latest syntax, and how to get that form set up with some simple validation and initial values.
- Open up your console and use to install the Redux Form release candidate:
Our tutorial will also be dependent on and , so make sure you have the latest versions of those installed as well.
- So just underneath our dependencies, outside of the scope of the component, add the following:
Handling the validation of our form can get messy if we do it “inline” as part of the render function of our component.
- So to clean that up and make it reusable (plus easier to manage), create a that returns the input and logic for any errors that our field receives:
Let’s also create a similar constant that will serve our input:
Now we need to define the redux form required property inside the render function of the component.
With the latest version of redux form available we take a look at the best way to create a form that starts with pre-populated fields and validation.
Continue reading “How to Create a Redux Form with Validation and Initialized Values”