Reactjs React.createElement,获取错误';无效的钩子调用。钩子只能在函数组件';

Reactjs React.createElement,获取错误';无效的钩子调用。钩子只能在函数组件';,reactjs,react-hooks,Reactjs,React Hooks,我有一个模态,模态渲染内部组件的方式是通过以下方式: get displayModalBody() { const {newComponent} = this.props return( <div> {React.createElement(newComponent, this.props)} </div> )

我有一个模态,模态渲染内部组件的方式是通过以下方式:

     get displayModalBody() {
         const {newComponent} = this.props
         return(
             <div>
                {React.createElement(newComponent, this.props)}
             </div>
         )

      }
我不再得到错误,它按预期工作。唯一的问题是我不能硬编码的组成部分,因为它的变化。。。有人知道为什么React.createElement方法在这种情况下不起作用,还有什么解决方案吗

   get displayModalBody() {
     return(
         <div>
           <HardcodedComponent {...this.props}/>
         </div>
     )

  }