Introduction to Reducer
Learn how to optimize the React applications with TypeScript.
We'll cover the following
React application challanges
Many examples of React applications tend to be small and easily understandable. But in the real world, React apps tend to grow to a scale that makes it impossible to keep all the context in our heads. This can often lead to unexpected bugs when a given value isn’t what we thought it would be. That object we thought had a certain property on it? It turns out it ended up being undefined
somewhere along the way. That function we passed in? Yeah, that’s undefined
too. That string we’re trying to match against? We misspelled it one night when we were working after hours.
Using TypeScript for the code quality
Using TypeScript in a React application enhances code quality by providing
State management with reducers
Large applications also tend to come with increasingly complicated state management. Reducers are a powerful pattern for managing a state in client-side applications. Reducers became popular with Redux, and are now built into React with the useReducer
hook, but they’re framework and language agnostic. At the end of the day, a reducer is just a function. Redux and React’s useReducer
adds functionality to trigger updates accordingly. We can use Redux with any frontend framework or without one altogether. We could also easily write our take on Redux if we were so inclined.
That said, Redux (and other implementations of the