The Redux Essentials tutorial is a "top-down" tutorial that teaches "how to use Redux the right way", using our latest recommended APIs and best practices. We have a variety of resources available to help you learn Redux. Redux Toolkit allows us to write shorter logic that's easier to read, while still following the same Redux behavior and data flow. With Redux Toolkit, that same logic looks like: Redux Toolkit simplifies the process of writing Redux logic and setting up the store. You can record user sessions and reproduce them just by replaying every action. It also enables very powerful developer tools, because it is possible to trace every mutation to the action that caused it. This architecture might seem like a lot for a counter app, but the beauty of this pattern is how well it scales to large and complex apps. This is exactly like how there is just one root component in a React app, but it is composed out of many small components. As your app grows, you split the root reducer into smaller reducers independently operating on the different parts of the state tree. In a typical Redux app, there is just a single store with a single root reducing function. Then you write a special function called a reducer to decide how every action transforms the entire application's state. Instead of mutating the state directly, you specify the mutations you want to happen with plain objects called actions. * we use a switch statement, but it's not required.įunction counterReducer ( state = ) * You can use any conditional logic you want in a reducer. * not mutate the state object, but return a new object if the state changes. * The root state value is usually an object. * The Redux state should contain only plain JS objects, arrays, and primitives. * A reducer's function signature is: (state, action) => newState * action object describing "what happened", and returns a new state value. * This is a reducer - a function that takes a current state value and an Redux Toolkit is available as a package on NPM for use with a module bundler or in a Node application: Simplify an existing application, Redux Toolkit can help you Whether you're a brand new Redux user setting up your first project, or an experienced user who wants to RTK includes utilities that help simplify many common use cases, including store setup,Ĭreating reducers and writing immutable update logic,Īnd even creating entire "slices" of state at once. Redux Toolkit builds in our suggested best practices, simplifies most Redux tasks, prevents common mistakes, and makes it easier to write Redux applications. It wraps around the Redux core, and contains packages and functions that we think are essential for building a Redux app. Redux Toolkit is our official recommended approach for writing Redux logic. It is tiny (2kB, including dependencies), but has a large ecosystem of addons available. You can use Redux together with React, or with any other view library. On top of that, it provides a great developer experience, such as live code editing combined with a time traveling debugger. It helps you write applications that behave consistently, run in different environments (client, server, and native), and are easy to test. Redux is a predictable state container for JavaScript apps.
0 Comments
Leave a Reply. |