我在Redux-Hooks中显示useSelector遇到问题

时间:2019-09-08 10:13:01

标签: javascript react-redux

当我尝试在应用程序中使用useSelector时,什么也看不到,但我确实看到了Redux的DevTools和控制台

这是我的Material-ui组件

显然我没有得到我想要的道具

  const Vacations = useSelector((state) => state.Vacations);//need props
  const User = useSelector((state)=> state.User);//need props
  const FollowCounter = useSelector((state) => state.FollowCounter);


  //----- redux and dispatch the action
  const dispatch = useDispatch();
  const followUP = () => dispatch(followplus());
  const getVacations = () => dispatch(fetch_Vacations());
  const getUsers = () => dispatch(fetch_Users());

  useEffect(() => {
    getVacations();
    getUsers();
  }, [])

这是我要向您展示的示例

        <Button size="small" color="primary">
                <Typography>
                  Follows={followcounter}
                </Typography>
              </Button>

在这里,我不确定是否应该在挂钩中,但是我也尝试这样做

function mapStateToProps(state) {
  console.log(state);
  return {
    followers: state.followers
  }
}
function mapDispachToProps(dispatch) {
  return {
    followUP: (followplus) => dispatch(followplus),
    getVacations: (fetch_Vacations) => dispatch(fetch_Vacations),
    getUsers: (fetch_Users) => dispatch(fetch_Users),
  }
}

export default connect(mapStateToProps, mapDispachToProps)(Vacation)

无论如何,我尝试了很多选择和很多视频,但是都没有成功

0 个答案:

没有答案