-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- 문제 페이지에서 사용자가 선택하는 문제를 전역으로 관리하기 위한 redux toolkit 세팅
- Loading branch information
1 parent
6ee43f4
commit 6bac4cd
Showing
8 changed files
with
180 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { createSlice } from '@reduxjs/toolkit'; | ||
import { Choice } from '../../types/Choice'; | ||
|
||
interface DataState { | ||
choices: Choice[]; | ||
} | ||
|
||
const initialState: DataState = { | ||
choices: [], | ||
}; | ||
|
||
export const choicesSlice = createSlice({ | ||
name: 'choices', | ||
initialState, | ||
reducers: {}, | ||
}); | ||
|
||
export default choicesSlice.reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { combineReducers } from '@reduxjs/toolkit'; | ||
import choices from './choices'; | ||
|
||
// reducer를 모아두는 rootreducer | ||
const reducer = combineReducers({ | ||
choices, | ||
}); | ||
|
||
export type ReducerType = ReturnType<typeof reducer>; | ||
export default reducer; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
import { TypedUseSelectorHook, useDispatch, useSelector } from 'react-redux'; | ||
import type { RootState, AppDispatch } from '../store'; | ||
|
||
// js처럼 사용하기 위한 커스텀 hook | ||
export const useAppDispatch = () => useDispatch<AppDispatch>(); | ||
export const useAppSelector: TypedUseSelectorHook<RootState> = useSelector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
// src/redux/store.ts | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import reducer from './redux/_reducers/rootReducer'; | ||
|
||
export const store = configureStore({ | ||
reducer, | ||
}); | ||
|
||
// Infer the `RootState` and `AppDispatch` types from the store itself | ||
export type RootState = ReturnType<typeof store.getState>; | ||
// Inferred type: {posts: PostsState, comments: CommentsState, users: UsersState} | ||
export type AppDispatch = typeof store.dispatch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export type Choice = { | ||
questionIndex: number; | ||
answer: string; | ||
}; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.