DEV Community

Discussion on: How to use Redux with TypeScript ?

Collapse
 
markerikson profile image
Mark Erikson

Hi, I'm a Redux maintainer. Unfortunately, the patterns shown in this article are very outdated and actively go against how we recommend writing Redux code today :(

Please note that "modern Redux" code is very different than what most older tutorials show. We've introduced newer APIs like Redux Toolkit, which is a set of utilities that provide a light abstraction to simplify the most common Redux tasks, and the React-Redux hooks API, which is generally easier to use than the traditional connect API.

I strongly recommend reading through the newly rewritten official tutorials in the Redux docs, which have been specifically designed to teach you how Redux works and show our recommended practices:

  • "Redux Essentials" tutorial: teaches "how to use Redux, the right way", by building a real-world app using Redux Toolkit
  • "Redux Fundamentals" tutorial: teaches "how Redux works, from the bottom up", by showing how to write Redux code by hand and why standard usage patterns exist, and how Redux Toolkit simplifies those patterns

For Redux+TS specifically, follow the patterns shown in the Redux core docs "Usage with TypeScript" page.

You should also read through the Redux "Style Guide" docs page, which explains our recommended patterns and best practices. Following those will result in better and more maintainable Redux apps.

In addition, the easiest way to start a new project is with the official Redux+TS template for Create-React-App. It comes with Redux Toolkit and the React-Redux hooks API already set up when the project is created, as well as pre-typed React-Redux hooks.

Collapse
 
tris909 profile image
Tran Minh Tri

Hi Hey, Thank you for your long reply. This tutorial here is actually from a Udemy code that I have done recently to study TypeScript.

If everyone read this. Please follow this guide link for the newest best practices.

Thank you all