mirror of
https://github.com/ershisan99/flashcards-docs.git
synced 2026-01-28 05:12:08 +00:00
lesson 3 temp
This commit is contained in:
61
pages/lesson-3/chapter-2.ru.mdx
Normal file
61
pages/lesson-3/chapter-2.ru.mdx
Normal file
@@ -0,0 +1,61 @@
|
||||
# RTK Query
|
||||
|
||||
## Установка
|
||||
|
||||
```bash filename="Terminal"
|
||||
pnpm i @reduxjs/toolkit react-redux
|
||||
```
|
||||
|
||||
## Создание стора
|
||||
|
||||
```ts filename="src/services/store.ts"
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {},
|
||||
middleware: getDefaultMiddleware => getDefaultMiddleware(),
|
||||
})
|
||||
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
export type RootState = ReturnType<typeof store.getState>
|
||||
```
|
||||
|
||||
## Подключение стора к приложению
|
||||
|
||||
```tsx filename="src/App.tsx"
|
||||
import { Provider } from 'react-redux'
|
||||
|
||||
import { Router } from '@/router'
|
||||
import { store } from '@/services/store'
|
||||
|
||||
export function App() {
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Router />
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
```
|
||||
|
||||
## Создание Api
|
||||
|
||||
```ts filename="src/services/auth/auth.ts"
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
export const authApi = createApi({
|
||||
reducerPath: 'authApi',
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: 'https://api.flashcards.andrii.es',
|
||||
credentials: 'include',
|
||||
}),
|
||||
endpoints: builder => {
|
||||
return {
|
||||
getMe: builder.query<any, void>({
|
||||
query: () => `auth/me`,
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const { useGetMeQuery } = authApi
|
||||
```
|
||||
Reference in New Issue
Block a user