ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • React Redux
    Front-end/React 2022. 3. 3. 23:19

    스토어 생성 후 컴포넌트에서 리덕스 스토어를 사용할수 있도록 Provider 컴포넌트로 감싸준다. 

    The <Provider> component makes the Redux store available to any nested components that need to access the Redux store.

    Since any React component in a React Redux app can be connected to the store, most applications will render a <Provider> at the top level, with the entire app’s component tree inside of it.

     

    컴포넌트를 리덕스와 연동하려면 react-redux에서 제공하는 connet()를 사용해야한다. 

    The connect() function connects a React component to a Redux store.

    It provides its connected component with the pieces of the data it needs from the store, and the functions it can use to dispatch actions to the store.

    It does not modify the component class passed to it; instead, it returns a new, connected component class that wraps the component you passed in.

    mapStateToProps와 mapDispatchToProps는 리덕스 스토어의 state와 dispatch을 각각 파라미터로 받아와 처리한다. 

    state and dispatch will be supplied to your mapStateToProps or mapDispatchToProps functions as the first argument.

    The returns of mapStateToProps and mapDispatchToProps are referred to internally as stateProps and dispatchProps, respectively. They will be supplied to mergeProps, if defined, as the first and the second argument, where the third argument will be ownProps. The combined result, commonly referred to as mergedProps, will then be supplied to your connected component.

    'Front-end > React' 카테고리의 다른 글

    [Polymorphic React Component] - 1  (1) 2022.11.24
    [Hooks] 훅스의 규칙  (0) 2022.09.17
    [React] useMemo와 useCallback  (0) 2022.06.28
    [ React ] 라이프사이클  (0) 2021.05.30
    리액트 소개  (0) 2021.05.28
Designed by Tistory.