mirror of
https://github.com/ershisan99/flashcards-example-project.git
synced 2025-12-17 20:59:31 +00:00
add store and base api
This commit is contained in:
11
src/App.tsx
11
src/App.tsx
@@ -1,3 +1,12 @@
|
||||
import { Provider } from 'react-redux'
|
||||
|
||||
import { Router } from '@/router'
|
||||
import { store } from '@/services/store'
|
||||
|
||||
export function App() {
|
||||
return <div>Hello</div>
|
||||
return (
|
||||
<Provider store={store}>
|
||||
<Router />
|
||||
</Provider>
|
||||
)
|
||||
}
|
||||
|
||||
14
src/router.tsx
Normal file
14
src/router.tsx
Normal file
@@ -0,0 +1,14 @@
|
||||
import { createBrowserRouter, RouteObject, RouterProvider } from 'react-router-dom'
|
||||
|
||||
const routes: RouteObject[] = [
|
||||
{
|
||||
path: '/',
|
||||
element: <div>hello</div>,
|
||||
},
|
||||
]
|
||||
|
||||
const router = createBrowserRouter(routes)
|
||||
|
||||
export const Router = () => {
|
||||
return <RouterProvider router={router} />
|
||||
}
|
||||
21
src/services/auth/auth.ts
Normal file
21
src/services/auth/auth.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react'
|
||||
|
||||
export const api = createApi({
|
||||
reducerPath: 'api',
|
||||
baseQuery: fetchBaseQuery({
|
||||
baseUrl: 'http://localhost:3333',
|
||||
credentials: 'include',
|
||||
prepareHeaders: headers => {
|
||||
headers.append('x-auth-skip', 'true')
|
||||
},
|
||||
}),
|
||||
endpoints: builder => {
|
||||
return {
|
||||
getMe: builder.query<any, void>({
|
||||
query: () => `v1/decks`,
|
||||
}),
|
||||
}
|
||||
},
|
||||
})
|
||||
|
||||
export const { useGetMeQuery } = api
|
||||
1
src/services/auth/index.ts
Normal file
1
src/services/auth/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from './auth.ts'
|
||||
13
src/services/store.ts
Normal file
13
src/services/store.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
import { configureStore } from '@reduxjs/toolkit'
|
||||
|
||||
import { api } from '@/services/auth'
|
||||
|
||||
export const store = configureStore({
|
||||
reducer: {
|
||||
[api.reducerPath]: api.reducer,
|
||||
},
|
||||
middleware: getDefaultMiddleware => getDefaultMiddleware().concat(api.middleware),
|
||||
})
|
||||
|
||||
export type AppDispatch = typeof store.dispatch
|
||||
export type RootState = ReturnType<typeof store.getState>
|
||||
Reference in New Issue
Block a user