-
Notifications
You must be signed in to change notification settings - Fork 0
/
tut.js
124 lines (83 loc) · 2.05 KB
/
tut.js
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
//* React Router Dom
//^ App.js for react-router
import './App.css'
import {
BrowserRouter as Router,
Routes,
Route,
} from "react-router-dom";
import { Navbar } from './components/index';
import { Home } from './pages/index';
function App() {
return (
<Router>
<Navbar />
<Routes>
<Route path='/' element={<Home />} />
</Routes>
</Router>
)
}
// export default App
//* Redux toolkit
// --STORE.js
import { configureStore } from '@reduxjs/toolkit'
export const store = configureStore({
reducer: {},
})
// SLICE.js
import { createSlice } from '@reduxjs/toolkit'
const initialState = {}
const counterSlice = createSlice({
name: '',
initialState,
reducers: {
increment(state) {
state.value++
}
},
extraReducers: (builder) => {
builder
.addCase(__, (state, action) => {
})
}
})
export const { } = counterSlice.actions
export default counterSlice.reducer
// -createAsyncThunk
const fetchUserById = createAsyncThunk(
'users/fetchByIdStatus',
async (u_, thunkAPI) => {
const response = await userAPI.fetchById(userId)
return response.data
}
)
// main js
import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App'
import './index.css'
import { Provider } from 'react-redux'
import { store } from './features/store'
ReactDOM.createRoot(document.getElementById('root')).render(
<React.StrictMode>
<Provider store={store}>
<App />
</Provider>
</React.StrictMode>,
)
// * Custom Axios
import axios from "axios";
export const globalApi =axios.create({
baseURL:import.meta.env.VITE_APP_
})
//* Context API
import { createContext } from "react";
const GlobalContext=createContext()
export const GlobalContextProivder=({children})=>{
return(
<GlobalContext value={{}}>
{children}
</GlobalContext>
)
}