FrontEnd/React
[FrontEnd] 리덕스 준비
문서폿
2018. 11. 13. 02:04
src에 보기와 같이 리덕스 디렉토리를 생성하고
// imports
// actions
// action creators
// initial state
const initialState = {
isLoggedIn : localStorage.getItem("jwt") || false
};
//reducer
function reducer(state =initialState, action){
switch(action.type){
default :
return state;
}
}
//reducer funtions
//exports
//reducer export
export default reducer;
위와 같이 작성한다
이 때, const initialState는 초기 상태를 객체로써 기억하고 보통 스토어에 담길 내용이다.
isLoggIn은 로그인시 생기는 토큰 값(권한)을 기억하기 위한 보관소이고
jwt가 Item일시에 True반환 아니면 false를 반환한다
function reducer는 상태와 액션을 받음