[Redux] useSelector, useDispatch

587 단어 reduxredux

useSelector ?

  • useSelector is a function that takes the current state as an argument and returns whatever data you want from it. It's very similiar to mapStateToProps() and it allows you to store the return values inside a variable within the scope of you functional components instead of passing down as props.
 const sidebarShow = useSelector((state) => state.sidebarShow);

useDispatch ? dispatch를 날리는 것. action을 날리면 된다.

react-redux 7버전 이후 부터 생긴 훅으로 인해 connect HOC를 사용하지 않아도 된다.

좋은 웹페이지 즐겨찾기