Skip to content

Commit 8ec3c1f

Browse files
committed
all style changed
1 parent 6d64ee8 commit 8ec3c1f

File tree

3 files changed

+16
-31
lines changed

3 files changed

+16
-31
lines changed

courses/react-js/advanced-level/redux-toolkit/lesson_1.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ npm install @reduxjs/toolkit react-redux
4242

4343
Redux Toolkit provides a `configureStore` function that simplifies store creation. It includes good defaults and automatically sets up the Redux DevTools extension.
4444

45-
```javascript
46-
// src/app/store.js
45+
```Javascript title="src/app/store.js"
4746
import { configureStore } from '@reduxjs/toolkit';
4847
import counterReducer from '../features/counter/counterSlice';
4948

@@ -60,8 +59,7 @@ export default store;
6059

6160
A slice is a collection of Redux reducer logic and actions for a single feature of your app. Redux Toolkit’s `createSlice` function automatically generates action creators and action types.
6261

63-
```javascript
64-
// src/features/counter/counterSlice.js
62+
```javascript title = "src/app/app.js"
6563
import { createSlice } from '@reduxjs/toolkit';
6664

6765
export const counterSlice = createSlice({
@@ -90,8 +88,7 @@ export default counterSlice.reducer;
9088

9189
Now that the store and slice are set up, you can use them in your React components. Use the `useSelector` hook to read state and the `useDispatch` hook to dispatch actions.
9290

93-
```javascript
94-
// src/features/counter/Counter.js
91+
```javascript title = "src/features/counter/counter.js
9592
import React from 'react';
9693
import { useSelector, useDispatch } from 'react-redux';
9794
import { increment, decrement, incrementByAmount } from './counterSlice';
@@ -121,8 +118,7 @@ export default Counter;
121118

122119
To make the Redux store available to your entire app, wrap your application in the `Provider` component from `react-redux`.
123120

124-
```javascript
125-
// src/index.js
121+
```javascript title = "src/index.js"
126122
import React from 'react';
127123
import ReactDOM from 'react-dom';
128124
import { Provider } from 'react-redux';

courses/react-js/advanced-level/redux-toolkit/lesson_2.md

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,7 @@ Creating an API utility for your application is an essential step to manage and
2525

2626
You'll often want to separate your API calls into a dedicated utility file. This approach allows you to centralize the logic for making HTTP requests, making your code more modular and easier to maintain.
2727

28-
```javascript
29-
// src/features/posts/postsAPI.js
28+
```javascript title = "src/features/posts/postsAPI.js"
3029
import axios from 'axios';
3130

3231
export const fetchPosts = () => {
@@ -40,8 +39,7 @@ export const fetchPosts = () => {
4039

4140
With the API utility created, you can now use it in your Redux slices to handle asynchronous actions. Redux Toolkit provides `createAsyncThunk` to simplify this process.
4241

43-
```javascript
44-
// src/features/posts/Posts.js
42+
```javascript title = "src/features/posts/Posts.js"
4543
import React, { useEffect } from 'react';
4644
import { useSelector, useDispatch } from 'react-redux';
4745
import { fetchPostsAsync } from './postsSlice';
@@ -88,8 +86,7 @@ For complex applications, it's important to structure your state effectively to
8886

8987
### 1. Normalizing State Structure
9088

91-
```javascript
92-
// src/features/entities/entitiesSlice.js
89+
```javascript title = "src/features/entities/entitiesSlice.js"
9390
import { createSlice } from '@reduxjs/toolkit';
9491

9592
const entitiesSlice = createSlice({
@@ -125,8 +122,7 @@ export default entitiesSlice.reducer;
125122

126123
Redux Toolkit provides `createEntityAdapter` to manage normalized state more efficiently. It includes helpers for common operations like adding, updating, and removing entities.
127124

128-
```javascript
129-
// src/features/posts/postsSlice.js
125+
```javascript title="src/features/posts/postsSlice.js"
130126
import { createSlice, createEntityAdapter } from '@reduxjs/toolkit';
131127
import { fetchPosts } from './postsAPI';
132128

courses/react-js/advanced-level/redux-toolkit/lesson_3.md

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ Middleware in Redux is a powerful way to extend the functionality of the store.
2828

2929
Redux Toolkit's `configureStore` makes it easy to add middleware to your Redux store.
3030

31-
```javascript
32-
// src/app/store.js
31+
```javascript title="src/app/store.js"
3332
import { configureStore, getDefaultMiddleware } from '@reduxjs/toolkit';
3433
import counterReducer from '../features/counter/counterSlice';
3534
import logger from 'redux-logger';
@@ -48,8 +47,7 @@ export default store;
4847

4948
You can write your own custom middleware to handle specific tasks. Middleware is a function that returns another function, which receives the `next` function and the `action`.
5049

51-
```javascript
52-
// src/middleware/customMiddleware.js
50+
```javascript title="src/middleware/customMiddleware.js"
5351
const customMiddleware = (storeAPI) => (next) => (action) => {
5452
console.log('Dispatching action:', action);
5553
let result = next(action);
@@ -64,8 +62,7 @@ export default customMiddleware;
6462

6563
Add the custom middleware to your Redux store using `configureStore`.
6664

67-
```javascript
68-
// src/app/store.js
65+
```javascript title="src/app/store.js"
6966
import { configureStore } from '@reduxjs/toolkit';
7067
import counterReducer from '../features/counter/counterSlice';
7168
import customMiddleware from '../middleware/customMiddleware';
@@ -86,7 +83,7 @@ export default store;
8683

8784
Sometimes you may want to reuse the same logic in different parts of your application. You can create a reusable slice that can be configured for different use cases.
8885

89-
```javascript
86+
```javascript title="src/features/toggle/toggleSlice.js"
9087
// src/features/toggle/toggleSlice.js
9188
import { createSlice } from '@reduxjs/toolkit';
9289

@@ -108,8 +105,7 @@ export default createToggleSlice;
108105

109106
You can create instances of the reusable slice for different parts of your state.
110107

111-
```javascript
112-
// src/features/toggle/toggleInstances.js
108+
```javascript title="src/fratures/toggle/toggleInstace.js"
113109
import createToggleSlice from './toggleSlice';
114110

115111
export const lightSlice = createToggleSlice('light');
@@ -128,8 +124,7 @@ export default {
128124

129125
Use Redux Toolkit's `combineReducers` to combine the reducers into a single reducer.
130126

131-
```javascript
132-
// src/app/rootReducer.js
127+
```javascript title = "src/app/rootReducer.js"
133128
import { combineReducers } from '@reduxjs/toolkit';
134129
import toggleReducers from '../features/toggle/toggleInstances';
135130

@@ -144,8 +139,7 @@ export default rootReducer;
144139

145140
Create the store with the combined reducer.
146141

147-
```javascript
148-
// src/app/store.js
142+
```javascript title = "src/app/store.js"
149143
import { configureStore } from '@reduxjs/toolkit';
150144
import rootReducer from './rootReducer';
151145

@@ -160,8 +154,7 @@ export default store;
160154

161155
Use the toggle slices in your components.
162156

163-
```javascript
164-
// src/features/toggle/LightSwitch.js
157+
```javascript title ="src/toggle/lightSwitch.js"
165158
import React from 'react';
166159
import { useSelector, useDispatch } from 'react-redux';
167160
import { toggleLight } from './toggleInstances';

0 commit comments

Comments
 (0)