1 | # Redux Toolkit
|
2 |
|
3 | [](https://travis-ci.org/reduxjs/redux-toolkit)
|
4 | [](https://www.npmjs.com/package/@reduxjs/toolkit)
|
5 | [](https://www.npmjs.com/package/@reduxjs/toolkit)
|
6 |
|
7 | **The official, opinionated, batteries-included toolset for efficient Redux development**
|
8 |
|
9 | (Formerly known as "Redux Starter Kit")
|
10 |
|
11 | ## Installation
|
12 |
|
13 | ### Using Create React App
|
14 |
|
15 | The recommended way to start new apps with React and Redux Toolkit is by using the [official Redux+JS template](https://github.com/reduxjs/cra-template-redux) for [Create React App](https://github.com/facebook/create-react-app), which takes advantage of React Redux's integration with React components.
|
16 |
|
17 | ```sh
|
18 | npx create-react-app my-app --template redux
|
19 | ```
|
20 |
|
21 | ### An Existing App
|
22 |
|
23 | Redux Toolkit is available as a package on NPM for use with a module bundler or in a Node application:
|
24 |
|
25 | ```bash
|
26 | # NPM
|
27 | npm install @reduxjs/toolkit
|
28 |
|
29 | # Yarn
|
30 | yarn add @reduxjs/toolkit
|
31 | ```
|
32 |
|
33 | It is also available as a precompiled UMD package that defines a `window.RTK` global variable.
|
34 | The UMD package can be used as a [`<script>` tag](https://unpkg.com/@reduxjs/toolkit/dist/redux-toolkit.umd.js) directly.
|
35 |
|
36 | ## Purpose
|
37 |
|
38 | The **Redux Toolkit** package is intended to be the standard way to write Redux logic. It was originally created to help address three common concerns about Redux:
|
39 |
|
40 | - "Configuring a Redux store is too complicated"
|
41 | - "I have to add a lot of packages to get Redux to do anything useful"
|
42 | - "Redux requires too much boilerplate code"
|
43 |
|
44 | We can't solve every use case, but in the spirit of [`create-react-app`](https://github.com/facebook/create-react-app) and [`apollo-boost`](https://dev-blog.apollodata.com/zero-config-graphql-state-management-27b1f1b3c2c3), 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.
|
45 |
|
46 | Because of that, this package is deliberately limited in scope. It does _not_ address concepts like "reusable encapsulated Redux modules", data caching, folder or file structures, managing entity relationships in the store, and so on.
|
47 |
|
48 | ## What's Included
|
49 |
|
50 | Redux Toolkit includes these APIs:
|
51 |
|
52 | - `configureStore()`: wraps `createStore` to provide simplified configuration options and good defaults. It can automatically combine your slice reducers, adds whatever Redux middleware you supply, includes `redux-thunk` by default, and enables use of the Redux DevTools Extension.
|
53 | - `createReducer()`: that lets you supply a lookup table of action types to case reducer functions, rather than writing switch statements. In addition, it automatically uses the [`immer` library](https://github.com/mweststrate/immer) to let you write simpler immutable updates with normal mutative code, like `state.todos[3].completed = true`.
|
54 | - `createAction()`: generates an action creator function for the given action type string. The function itself has `toString()` defined, so that it can be used in place of the type constant.
|
55 | - `createSlice()`: 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.
|
56 | - `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
|
57 | - `createEntityAdapter`: generates a set of reusable reducers and selectors to manage normalized data in the store
|
58 | - The `createSelector` utility from the [Reselect](https://github.com/reduxjs/reselect) library, re-exported for ease of use.
|
59 |
|
60 | ## Documentation
|
61 |
|
62 | The Redux Toolkit docs are available at **https://redux-toolkit.js.org**.
|