: 데이터를 GET(조회)할 때 사용
: 데이터를 create, update, delete (수정)할 때 사용
const handleSubmit = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
if (inputValue.occupation == '') {
alert('직업을 입력해 주세요!');
return;
}
mutate();
};
const setOptionInfo = () => {
return axios.post(
'http://localhost:8000/user/introduction',
{
introduction_tags: [
inputValue.style,
inputValue.family,
inputValue.occupation,
],
},
{
headers: { Authorization: `Bearer ${userInfo.access_token}` },
}
);
};
const { isLoading, isError, mutate } = useMutation(setOptionInfo, {
onSuccess: () => {
alert('뉴뉴에 오신 것을 환영합니다 (>_<)/');
navigate('/');
},
retry: false,
});
mutate()
함수가 실행!//reducer
export interface TokenType {
value: string;
}
const initialState: TokenType = {
value: '',
};
export const tokenSlice = createSlice({
name: 'tokenState',
initialState,
reducers: {
addToken: (state, action: PayloadAction<string>) => {
state.value = action.payload;
},
removeToken: state => {
state.value = '';
},
},
});
//store
export interface RootState {
tokenState: {
value: string;
};
}
export default configureStore({
reducer: {
tokenState: tokenReducer,
},
});
// login.tsx
// refresh token dispatch를 통해 store에 저장
const dispatch = useDispatch();
dispatch(addToken(kakao.data.refresh_token));
// store에 저장된 refresh token 불러오기
const refreshToken = useSelector(
(state: RootState) => state.tokenState.value
);
: state를 저장, action을 전달할 때 사용
: state를 조회(참조)할 때 사용