- ๋ถ๋ชจ ์ปดํฌ๋ํธ
App.js
์์ ๋ชจ๋ ๋ฐ์ดํฐ๋ฅผ ๊ด๋ฆฌstate
store
์์ ์ด๋ฅผ ์์ ํ๊ณ ๊ด๋ฆฌaction
๊ณผreducer
์ผ๋ก ๋ฐ์ดํฐ ๊ฐ์ ๋ณํ์ํจ๋คaxios
์ ํต์ ํ๊ธฐ ์ํmiddleware
๋ก
redux-thunk ๋ฅผ ์ฌ์ฉ
Redux
๋ฅผ ์ ํํ๋ค.npm i --save react-redux redux
npm i redux-thunk
src
lib
store
cotainers (๋ฆฌ๋์ ์๋ํ๋ ๊ณต๊ฐ)
components (view ๋ด๋น)
screens (๊ตฌํ ์คํฌ๋ฆฐ)
redux
๋ก๋ถํฐ createStore, applyMiddleware
ํจ์๋ฅผ ๊ฐ์ ธ์ค๊ณ redux-thunk
๋ก๋ถํฐ thunk
๋ฅผ ๊ฐ์ ธ์ ๋ฏธ๋ค์จ์ด๋ฅผ ์ ์ฉํ ์คํ ์ด๋ฅผ ์์ฑํ๋ค.
import { createStore, applyMiddleware } from "redux";
import rootReducers from "./reducers/rootReducers";
import thunk from 'redux-thunk'
const store = createStore(rootReducers, applyMiddleware(thunk));
export default store;
const USER_URL : "api/user"
- ๊ฐํธ ๋น๋ฐ๋ฒํธ ๋ก๊ทธ์ธ
GET
- ํธ๋ํฐ ๋ฌธ์ ์ธ์ฆ
GET, POST
- ๋ฌธ์ ์ธ์ฆ ์ ํจ์๊ฐ
- ์ ๋ถ์ฆ ๋ฑ๋ก
POST
- ๋ฐฑ์ ์ฆ๋ช ์ ๋ฑ๋ก
POST
- ๊ฐํธ ๋น๋ฐ๋ฒํธ ์ค์
POST
- ๊ฐํธ ๋น๋ฐ๋ฒํธ ์ฌํ์ธ
GET
- ๋น๋ฐ๋ฒํธ ๋ณ๊ฒฝ์ ๋ฌธ์ ์ธ์ฆ
GET, POST
- ๋น๋ฐ๋ฒํธ ์ฌ์ค์
PUT
state
๋ง! ๊ด๋ จ์๋ action
์ type์ด ํ๋์ด๋ค.//password export const SET_PASSWORD = "SET_PASSWORD"; export const RESET_PASSWORD = "RESET_PASSWORD"; //idCard export const REGISTER_ID_CARD = "REGISTER_ID_CARD"; export const REGISTER_VACCINE_PASS = "REGISTER_VACCINE_PASS"; //re_password export const CONFIRM_PASSWORD = "CONFIRM_PASSWORD"; export const MODIFY_PASSWORD = "MODIFY_PASSWORD";
api ํต์
๊ณผ ๊ด๋ จ๋ action
์ _SUCCESS
, _FAILURE
๋ฅผ ์ถ๊ฐํ์ฌ redux-thunk
๋ฅผ ์ ์ฉํ ์ ์๋๋ก ํ๋ค. //login export const LOGIN = "LOGIN"; export const LOGIN_SUCCESS = "LOGIN_SUCCESS"; export const LOGIN_FAILURE = "LOGIN_FAILURE"; //autoLogin export const AUTO_LOGIN = "AUTO_LOGIN"; export const AUTO_LOGIN_SUCCESS = "AUTO_LOGIN_SUCCESS"; export const AUTO_LOGIN_FAILURE = "AUTO_LOGIN_FAILURE";
๋ชจ๋ reducer
๋ฅผ ๊ฐ์ ธ์ combineReducers
๋ก ํ๋ฒ์ root
๋ฅผ ๋ง๋ค์ด์ค๋ค
import { combineReducers } from "redux";
import loginReducer from "./login";
import authReducer from "./auth";
import userReducer from "./user";
const rootReducers = combineReducers({
login: loginReducer
auth: authReducer,
user: userReducer,
});
export default rootReducers;