๐ reference link:
1. Redux docs
https://redux.js.org/style-guide/#structure-files-as-feature-folders-with-single-file-logic
Because of this,ย we recommend that most applications should structure files using a "feature folder" approachย (all files for a feature in the same folder). Within a given feature folder,ย the Redux logic for that feature should be written as a single "slice" file, preferably using the Redux Toolkitย
createSlice
API. (This is also known as theย "ducks" pattern). While older Redux codebases often used a "folder-by-type" approach with separate folders for "actions" and "reducers", keeping related logic together makes it easier to find and update that code.
Erik Rasmussen ์ ์
์ก์
ํ์
, ์ก์
์์ฑ ํจ์, ๋ฆฌ๋์๋ฅผ ๊ฐ๊ฐ์ ๋ณ๋์ ํ์ผ(ํด๋)๊ฐ ์๋๋ผ
ํ๋์ module
์ฒ๋ผ ํ ํ์ผ ์์ ์์ฑํ๋ค.
reducer๋ export default๋ก ๋ด๋ณด๋
export default function reducer( state={}, action={} ){
switch (์ก์
ํ์
) {
// ๋ฆฌ๋์
default: return state;
}
}
actionํจ์๋ export๋ก ๋ด๋ณด๋
export function createWidget( widget ){
return { type: CREATE, widget }
}
์ก์ ํ์ ์ ์ ์ํ ๋ reducer/ACTION_TYPE ํํ๋ก ์ ์
const CREATE = "widgets/CREATE"
์ ๋์ฌ(reducer)๋ฅผ ๋ถ์ฌ์ฃผ๋ ์ด์ ?
- ์๋ก ๋ค๋ฅธ ๋ฆฌ๋์์์ ์ก์ ์ด๋ฆ์ด ์ค์ฒฉ๋๋ ๊ฒ์ ๋ฐฉ์ง