You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/tutorials/quick-start.md
+59-70Lines changed: 59 additions & 70 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,49 +7,47 @@ hide_title: true
7
7
8
8
9
9
10
-
# React Redux Quick Start
10
+
# Angular Redux Quick Start
11
11
12
12
:::tip What You'll Learn
13
13
14
-
- How to set up and use Redux Toolkit with React Redux
14
+
- How to set up and use Redux Toolkit with Angular Redux
15
15
16
16
:::
17
17
18
18
:::info Prerequisites
19
19
20
20
- Familiarity with [ES6 syntax and features](https://www.taniarascia.com/es6-syntax-and-feature-overview/)
21
-
- Knowledge of React terminology: [JSX](https://react.dev/learn/writing-markup-with-jsx), [State](https://react.dev/learn/state-a-components-memory), [Function Components, Props](https://react.dev/learn/passing-props-to-a-component), and [Hooks](https://react.dev/reference/react#)
21
+
- Knowledge of Angular terminology: [State](https://angular.dev/essentials/managing-dynamic-data), [Components, Props](https://angular.dev/essentials/components), and [Signals](https://angular.dev/guide/signals)
22
22
- Understanding of [Redux terms and concepts](https://redux.js.org/tutorials/fundamentals/part-2-concepts-data-flow)
23
23
24
24
:::
25
25
26
26
## Introduction
27
27
28
-
Welcome to the React Redux Quick Start tutorial! **This tutorial will briefly introduce you to React Redux and teach you how to start using it correctly**.
28
+
Welcome to the Angular Redux Quick Start tutorial! **This tutorial will briefly introduce you to Angular Redux and teach you how to start using it correctly**.
29
29
30
30
### How to Read This Tutorial
31
31
32
32
This page will focus on just how to set up a Redux application with Redux Toolkit and the main APIs you'll use. For explanations of what Redux is, how it works, and full examples of how to use Redux Toolkit, see [the Redux core docs tutorials](https://redux.js.org/tutorials/index).
33
33
34
-
For this tutorial, we assume that you're using Redux Toolkit and React Redux together, as that is the standard Redux usage pattern. The examples are based on [a typical Create-React-App folder structure](https://create-react-app.dev/docs/folder-structure) where all the application code is in a `src`, but the patterns can be adapted to whatever project or folder setup you're using.
35
-
36
-
The [Redux+JS template for Create-React-App](https://github.com/reduxjs/cra-template-redux) comes with this same project setup already configured.
34
+
For this tutorial, we assume that you're using Redux Toolkit and Angular Redux together, as that is the standard Redux usage pattern. The examples are based on [a typical Angular CLI folder structure](https://angular.dev/tools/cli) where all the application code is in a `src`, but the patterns can be adapted to whatever project or folder setup you're using.
37
35
38
36
## Usage Summary
39
37
40
-
### Install Redux Toolkit and React Redux
38
+
### Install Redux Toolkit and Angular Redux
41
39
42
-
Add the Redux Toolkit and React Redux packages to your project:
40
+
Add the Redux Toolkit and Angular Redux packages to your project:
43
41
44
42
```sh
45
-
npm install @reduxjs/toolkit react-redux
43
+
npm install @reduxjs/toolkit angular-redux
46
44
```
47
45
48
46
### Create a Redux Store
49
47
50
48
Create a file named `src/app/store.js`. Import the `configureStore` API from Redux Toolkit. We'll start by creating an empty Redux store, and exporting it:
This creates a Redux store, and also automatically configure the Redux DevTools extension so that you can inspect the store while developing.
61
59
62
-
### Provide the Redux Store to React
60
+
### Provide the Redux Store to Angular
61
+
62
+
Once the store is created, we can make it available to our Angular components by putting an Angular Redux `provideRedux` in our application's `providers` array in `src/main.ts`. Import the Redux store we just created, put a `provideRedux` in your application's `providers` array, and pass the store as a prop:
63
63
64
-
Once the store is created, we can make it available to our React components by putting a React Redux `<Provider>` around our application in `src/index.js`. Import the Redux store we just created, put a `<Provider>` around your `<App>`, and pass the store as a prop:
### Use Redux State and Actions in React Components
145
-
146
-
Now we can use the React Redux hooks to let React components interact with the Redux store. We can read data from the store with `useSelector`, and dispatch actions using `useDispatch`. Create a `src/features/counter/Counter.js` file with a `<Counter>` component inside, then import that component into `App.js` and render it inside of `<App>`.
### Use Redux State and Actions in Angular Components
139
+
140
+
Now we can use the Angular Redux inject functions to let Angular components interact with the Redux store. We can read data from the store with `useSelector`, and dispatch actions using `useDispatch`. Create a `src/features/counter/counter.component.ts` file with a `<app-counter>` component inside, then import that component into `app.component.ts` and render it inside of `<app-root>`.
Now, any time you click the "Increment" and "Decrement buttons:
181
170
182
171
- The corresponding Redux action will be dispatched to the store
183
172
- The counter slice reducer will see the actions and update its state
184
-
- The `<Counter>` component will see the new state value from the store and re-render itself with the new data
173
+
- The `<app-counter>` component will see the new state value from the store and re-render itself with the new data
185
174
186
175
## What You've Learned
187
176
188
-
That was a brief overview of how to set up and use Redux Toolkit with React. Recapping the details:
177
+
That was a brief overview of how to set up and use Redux Toolkit with Angular. Recapping the details:
189
178
190
179
:::tip Summary
191
180
192
181
-**Create a Redux store with `configureStore`**
193
182
-`configureStore` accepts a `reducer` function as a named argument
194
183
-`configureStore` automatically sets up the store with good default settings
195
-
-**Provide the Redux store to the React application components**
196
-
- Put a React Redux `<Provider>` component around your `<App />`
184
+
-**Provide the Redux store to the Angular application components**
185
+
- Put a Angular Redux `provideRedux` provider factory in your `bootstrapApplication`'s `providers` array
197
186
- Pass the Redux store as `<Provider store={store}>`
198
187
-**Create a Redux "slice" reducer with `createSlice`**
199
188
- Call `createSlice` with a string name, an initial state, and named reducer functions
200
189
- Reducer functions may "mutate" the state using Immer
201
190
- Export the generated slice reducer and action creators
202
-
-**Use the React Redux `useSelector/useDispatch` hooks in React components**
203
-
- Read data from the store with the `useSelector` hook
204
-
- Get the `dispatch` function with the `useDispatch` hook, and dispatch actions as needed
191
+
-**Use the Angular Redux `injectSelector/injectDispatch` injections in Angular components**
192
+
- Read data from the store with the `injectSelector` injection
193
+
- Get the `dispatch` function with the `injectDispatch` injection, and dispatch actions as needed
205
194
206
195
:::
207
196
@@ -219,4 +208,4 @@ Here's the complete Counter application as a running CodeSandbox:
219
208
220
209
## What's Next?
221
210
222
-
We recommend going through [**the "Redux Essentials" and "Redux Fundamentals" tutorials in the Redux core docs**](https://redux.js.org/tutorials/index), which will give you a complete understanding of how Redux works, what Redux Toolkit and React Redux do, and how to use it correctly.
211
+
We recommend going through [**the "Redux Essentials" and "Redux Fundamentals" tutorials in the Redux core docs**](https://redux.js.org/tutorials/index), which will give you a complete understanding of how Redux works, what Redux Toolkit and Angular Redux do, and how to use it correctly.
0 commit comments