Redux

taeheech·2020년 8월 17일

Redux는 application의 전체상태(state)를 관리하는 library.

Action

상태변화를 일으키는 현상
data type: object
type이라는 property를 항상 가지고있다 (어떤 행동을 설명하는 조작정보 string type)
payload를 가질수있다(optional) (특정 액션에 부가적인 데이터 전달)

creator

dispatch

action을 모든 reducer에 전달하기때문에
type을 비교해서 ..
defalt

reducer

store가 가지고있는 state를 변화시키는 함수

첫번째인자: 이전의state
두번째인자: action
함수내용: action의 내용(type)에 따라 state를 변화

기존에state가 정해져있지 않을때 initial state를 첫번째 인자에 넣어준다.
const initial_state = 0; (==>자바스크립트문법)
function balance (state=initial_state , action) {
}

store

리덕스는 createStore()함수로 store 생성
app에 하나만
app의 전체상태
store 생성할 때 reducer필요 (const store= createStore(Reducer))

기능들을 불러올때
react redux
redux
다름.
redux는 react 에서만 쓰이는 라이브러리가아니기때문에
가지고있는 기능들이 다름

참고 : https://yeri-kim.github.io/posts/redux/

0개의 댓글