React์ Redux๋ก ๊ตฌํํ API์๋ฒ์ ํต์ ํ์ฌ ์๋ํ๋ ๋๊ธ ๊ฒ์ํ
-
json-server๋ฅผ ์ฌ์ฉํ์ฌ Mock API ์ฌ์ฉ
-
๋ฐฐํฌ : heroku
React
- styled-components
Redux-thunk
- Container components์ Presentational components ๋ถ๋ฆฌํ์ฌ ์์ฑ
- Pagination
- ๋๊ธ ์์ฑ ํ, 1 ํ์ด์ง๋ก ์ด๋ + form ์ด๊ธฐํ
- ๋๊ธ ์์ ํ, ํ์ฌ ๋ณด๊ณ ์๋ ํ์ด์ง ์ ์ง + form ์ด๊ธฐํ
- ๋๊ธ ์ญ์ ํ, 1 ํ์ด์ง๋ก ๋์์ค๊ธฐ
-
api
- GET, POST, PUT, DELETE
-
CommentListContainer
- CommentList component : ํ์ด์ง์ ๋ฐ๋ฅธ comments๋ฅผ ๋ฐ์์ค๋ ์ปดํฌ๋ํธ
-
FormContainer
- Form component : form ์์์ ์ ๋ฌ, ๋ฐ์์ค๋ ์ปดํฌ๋ํธ
-
PageListContainer
- pageList component : ์ด comment๋ฅผ ๋ฐ์์์ page number์ ์ ๋ฌํ๋ ์ปดํฌ๋ํธ
//reducerUtils
export const reducerUtils = {
initial: (data = []) => ({
loading: false,
data,
error: null,
}),
loading: (prevState) => ({
loading: true,
data: prevState,
error: null,
}),
success: (payload) => ({
loading: false,
data: payload,
error: null,
}),
error: (error) => ({
loading: false,
data: null,
error: error,
}),
};
//createThunk
export const createPromiseThunk = (type, promiseCreator) => {
const [SUCCESS, ERROR] = [`${type}_SUCCESS`, `${type}_ERROR`];
const thunkCreator = (param) => async (dispatch) => {
dispatch({ type });
try {
const payload = await promiseCreator(param);
dispatch({
type: SUCCESS,
payload,
});
} catch (e) {
dispatch({
type: ERROR,
payload: e,
error: true,
});
}
};
return thunkCreator;
};
//handleAsyncActions
export const handleAsyncActions = (type, key) => {
const [SUCCESS, ERROR] = [`${type}_SUCCESS`, `${type}_ERROR`];
const reducer = (state, action) => {
switch (action.type) {
case type:
return {
...state,
[key]: reducerUtils.loading(),
};
case SUCCESS:
return {
...state,
[key]: reducerUtils.success(action.payload),
};
case ERROR:
return {
...state,
[key]: reducerUtils.error(action.payload),
};
default:
return state;
}
};
return reducer;
};