我的应用程序遇到问题,我想根据已登录的用户ID从用户集合中检索一个数组Lessons。 我正在使用redux thunk,jwt auth
我试图在componentDidmount中分派我的getMyLessons,但是它将this.props.auth.user用作null参数,但是如果我在render()上使用它,它会加载(它会冻结但会加载,哈哈),所以我认为lycecicle问题
class DashboardSidebar extends Component {
componentDidmount(){
this.props.getMyLessons(this.props.auth.user._id);
}
static propTypes = {
auth: PropTypes.object.isrequired,lesson: PropTypes.object.isrequired,getMyLessons: PropTypes.func.isrequired
}
const mapstatetoProps = (state) => ({
auth: state.auth,lesson: state.lesson
});
export default connect(mapstatetoProps,{ getMyLessons })(DashboardSidebar);