Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/function but got: object

前端 未结 30 1079
孤城傲影
孤城傲影 2020-11-22 06:53

I am getting this error:

Uncaught Error: Invariant Violation: Element type is invalid: expected a string (for built-in components) or a class/funct

30条回答
  •  终归单人心
    2020-11-22 07:26

    In addition to import/export issues mentioned. I found using React.cloneElement() to add props to a child element and then rendering it gave me this same error.

    I had to change:

    render() {
      const ChildWithProps = React.cloneElement(
        this.props.children,
        { className: `${PREFIX}-anchor` }
      );
    
      return (
        
    ...
    ); }

    to:

    render() {
      ...
      return (
        
    ); }

    See the React.cloneElement() docs for more info.

提交回复
热议问题