-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathINSTRUCTION.txt
70 lines (54 loc) · 2.43 KB
/
INSTRUCTION.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
****************************************************************************************************
1. Create a new React app with TypeScript and Redux Toolkit:
- Go to redux document (https://redux.js.org/) to know how to use Redux with TypeScript.
Now, you will see that there is a Redux+TS template for Create-React-App.
- Standard Redux Toolkit Project Setup with TypeScript:
+ To create a React app in the current folder:
npx create-react-app . --template redux-typescript
+ To create a React app in a new folder:
npx create-react-app my-app --template redux-typescript
****************************************************************************************************
2. Notes:
- Go to src/app/hooks.ts, you will see that we should use `useAppDispatch` and `useAppSelector`
instead of `useDispatch` and `useSelector`.
****************************************************************************************************
3. Project setup:
- Open tsconfig.json:
+ In compilerOptions, add:
"baseUrl": "./src"
****************************************************************************************************
4. ESLint, Prettier, Husky (uncompleted):
- eslint:
+ Because we used create-react-app script, we are already have eslint libraries,
so we don't need to add them to our package.json file explicitly.
+ Add configuration files for eslint:
.eslintrc
.eslintignore
- prettier:
+ Install:
npm install --save-dev --save-exact prettier
+ Add configuration files for prettier:
.prettierrc
.prettierignore
****************************************************************************************************
5. Apply a middleware in redux-toolkit:
- You must know:
+ redux-saga is a redux middleware.
- If you want to customize the list of middleware,
you can supply an array of middleware functions to configureStore.
(https://redux-toolkit.js.org/api/getDefaultMiddleware#intended-usage)
- Redux Saga:
+ Install:
npm install redux-saga
- Apply redux-saga middleware:
Go to src/app/store.ts, customize configureStore to apply redux-saga and other middlewares.
For example:
const sagaMiddleware = createSagaMiddleware();
export const store = configureStore({
reducer: {
counter: counterReducer,
},
middleware: (getDefaultMiddleware) =>
getDefaultMiddleware().concat(sagaMiddleware),
});
- Create and run Sagas.