简体   繁体   English

将参数从 HOC 功能组件传递到组件不起作用

[英]pass parameters from HOC functional component to component doesn't work

I have HOC component and when I set a breakpoint I get the data properly, but when I'm passing the parameters to the component I don't get the props right我有 HOC 组件,当我设置断点时,我会正确获取数据,但是当我将参数传递给组件时,我没有正确获取道具

    const { loading, error, data } = useQuery(GET_STUDENTS);

    return (
        <Component studentsLoading={loading} error={error} students={data && data.students} {...props} />
    );
};

and the passed in component looks like that传入的组件看起来像这样

const StudentList = ({error, studentsLoading, students}) => { }

export default withStudent(StudentList);

Since you said you are not getting props right, you are most likely overwriting HOC props with ...props thus move it up and see if that works.既然你说你没有得到正确的道具,你很可能用...props覆盖 HOC 道具,因此将其向上移动,看看是否有效。

    <Component {...props} studentsLoading={loading} error={error} students={data && data.students}  />
               ^^^^^^^^^^

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM