5/18/2023 0 Comments Redux toolkitIt is intended to simplify common cases for loading data in a web application, eliminating the need to hand-write data fetching & caching logic yourself. It is purpose-built to solve the use case of data fetching and caching, supplying a compact, but powerful toolset to define an API interface layer for your app. RTK Query is provided as an optional addon within the package. The createSelector() utility from the Reselect library, re-exported for ease of use. ![]() createEntityAdapter(): generates a set of reusable reducers and selectors to manage normalized data in the store.createAsyncThunk(): accepts an action type string and a function that returns a promise, and generates a thunk that dispatches pending/resolved/rejected action types based on that promise.A lightweight alternative to Redux async middleware like sagas and observables. createListenerMiddleware(): lets you define "listener" entries that contain an "effect" callback with additional logic, and a way to specify when that callback should run based on dispatched actions or state changes.Accepts an object of reducer functions, a slice name, and an initial state value, and automatically generates a slice reducer with corresponding action creators and action types. createSlice(): combines createReducer() + createAction().The function itself has toString() defined, so that it can be used in place of the type constant. createAction(): generates an action creator function for the given action type string.In addition, it automatically uses the immer library to let you write simpler immutable updates with normal mutative code, like = true. createReducer(): lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements.It can automatically combine your slice reducers, add whatever Redux middleware you supply, includes redux-thunk by default, and enables use of the Redux DevTools Extension. configureStore(): wraps createStore to provide simplified configuration options and good defaults.It's optional, but can eliminate the need to hand-write data fetching logic yourself. It's included in the package as a separate set of entry points. Redux Toolkit also includes a powerful data fetching and caching capability that we've dubbed "RTK Query". It does not address concepts like "reusable encapsulated Redux modules", folder or file structures, managing entity relationships in the store, and so on. We can't solve every use case, but in the spirit of create-react-app, we can try to provide some tools that abstract over the setup process and handle the most common use cases, as well as include some useful utilities that will let the user simplify their application code.īecause of that, this package is deliberately limited in scope. "Redux requires too much boilerplate code"."I have to add a lot of packages to get Redux to do anything useful"."Configuring a Redux store is too complicated". ![]() It was originally created to help address three common concerns about Redux: ![]() ![]() The Redux Toolkit package is intended to be the standard way to write Redux logic. The UMD package can be used as a tag directly. Yarn add is also available as a precompiled UMD package that defines a window.RTK global variable.
0 Comments
Leave a Reply. |