Created
March 2, 2021 01:21
-
-
Save JaysonChiang/04bc2dbbec90b4b8c2c02daae6a8d064 to your computer and use it in GitHub Desktop.
useSelector with DefaultRootState
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
import { combineReducers } from 'redux'; | |
import todosReducer from './todosReducer'; | |
const reducers = combineReducers({ | |
todos: todosReducer, | |
}); | |
export default reducers; | |
export type RootState = ReturnType<typeof reducers>; |
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
import { useSelector } from './useSelector'; | |
const TodoList: React.FC = () => { | |
const { todos } = useSelector((state) => state.todos); | |
return ( | |
<ul> | |
{todos.map((todo) => ( | |
<li>{todo}</li> | |
))} | |
</ul> | |
); | |
}; | |
export default TodoList; |
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
import { useSelector as _useSelector, TypedUseSelectorHook } from 'redux-redux'; | |
import { RootState } from './reducer'; | |
export const useSelector: TypedUseSelectorHook<RootState> = _useSelector; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment