리액트,타입스크립트

클래스형 컴포넌트에서 Redux 정보 가져오기 (connect)

JUN0126 2022. 4. 29. 16:50

 

const mapStateToProps = state => {
  return {
    darkMode: state.darkMode
  }
}

// redux에 담겨 있는 state를 사용하기 위한 map 설정 


const mapDispatchToProps = dispatch => {
  return {
    changeTheme: () => dispatch(this.props.changeTheme())
  }
}
// redux에 담겨 있는 dispatch를 연결해주기 위한 map 설정


export default connect(
  mapStateToProps,
  mapDispatchToProps
)(ContentItem)

// 위에서 설정한 두개의 map을 연결하기 위한 connect 설정

 

 

참고 : https://react.vlpt.us/redux/09-connect.html

'리액트,타입스크립트' 카테고리의 다른 글

javascript key값으로 배열 묶기 (groupby)  (0) 2022.04.20
React.memo 활용법  (0) 2021.06.30
React 이벤트 핸들러 전달  (0) 2021.04.15