Hooks are awesome. Well, I suppose it depends on what kind of hook you are talking about so let me clarify a bit. React hooks are awesome. They simplify our react components and are extremely powerful and diverse. You may have dabbled in hooks using things like useState and useEffect, or maybe you’re an old hook pro! Either way I hope I can share with you a new and unique way to simplify (in my opinion) your forms in react with the useReducer hook. useReducer becomes more powerful the larger and more complex your form is, but can still help to simplify your code in smaller forms. In this article we’re going to use this as our example form:

Sample form

Basic form

If you’re new to hooks don’t worry, I’ll try to bring you up to speed before we get into using useReducer. If you’re already a hook pro looking for a new tool skip to the useReducer section below.




#web-development #javascript #react #programming #react-hook

Using useReducer for Forms in React
5.05 GEEK