我有一个模态,模态在内部渲染组件的方式是通过
Route::middleware('can:isTutor')->group(function() {
Route::post('/home','TuteurEtudiantController@loginkid')->name('loginkid');
});
唯一的问题是所创建的元素之一具有一个子元素,该子元素是功能组件并使用钩子。所以当我使用上面的代码时,我得到了错误
get displayModalBody() {
const {newComponent} = this.props
return(
<div>
{React.createElement(newComponent, this.props)}
</div>
)
}
但是...如果我像这样对我的组件进行硬编码:
Invalid hook call. Hooks can only be called inside of the body of a function component. This could happen for one of the following reasons:
1. You might have mismatching versions of React and the renderer (such as React DOM)
2. You might be breaking the Rules of Hooks
3. You might have more than one copy of React in the same app
我不再收到错误,它可以按预期工作。唯一的问题是我无法对其进行更改的组件进行硬编码...有人知道为什么React.createElement方法在这种情况下不起作用以及任何解决方案吗?