tbnsok40 / Redux-tutorial

Prototype for Description publishing in Medical Institute ๐Ÿฅ

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

  • ๋ฆฌ๋•์Šค ์„ค์น˜ npm i redux react-redux redux-thunk redux-devtools-extension

  • store.js ์ƒ์„ฑ

  • ํ•„์š”ํ•œ ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์ž‘์„ฑ

  • App.js ๋‚ด๋ถ€์— Provider, store import

  • Provider ๋กœ ์ „์ฒด ๊ฐ์‹ธ๊ธฐ

  • reducers ํŒŒ์ผ ์ƒ์„ฑ

  • ๋‚ด๋ถ€์— index.js ์ƒ์„ฑ

  • ํ™˜์ž ๊ฐ์ฒด post๋กœ ์ƒ์„ฑ --> db.json์— "patients":{} ๋งŒ๋“ค์ง€ ์•Š๊ณ , ๊ณง๋ฐ”๋กœ fetch ๊ฐ€๋Šฅํ• ๊นŒ?

(๋ณ‘์› ๊ฐœ์ธ์ •๋ณด๋™์˜์„œ ๋ฐœ๊ธ‰ ๊ธฐ๋Šฅ => ๋ฐœ๊ธ‰๋œ ์„œ๋ฅ˜๋Š” ์–ด๋–ป๊ฒŒ ์ €์žฅํ•  ๊ฒƒ์ธ)

  • push ๊ฐ€ ์™œ ์•ˆ๋ผ?

State is immutable, that's the rule of redux.

Mutaion in state is not recommended.

Instead mutating the state, just return another object. for example using filter method in array state is a. good method to delete some elements in array. Because filter() method just return a new state(array) instead mutate a state.

Redux is just a function.

Dispatching actions, and modifying the data(states) through the actions.

it is good to separate functions as its minimum responsiblity, dispatchors should only perform dispatching actions, and those actions will get an action type and data(payload).

So that the reducers will change the state(data) and we can use those updated data through the 'getState() method'.

In Redux Middleware, Reducer is the only place that states of data modified, so that it is easy to handle the data and states.

If we don't use Redux, all data and states are handled in the component level which will occur big difficulty in controlling data because the states will be separated in all of components.

About

Prototype for Description publishing in Medical Institute ๐Ÿฅ


Languages

Language:JavaScript 92.7%Language:HTML 4.3%Language:CSS 3.0%