我有GetProfile类来扩展React.Component并在render中返回状态。我想用React Router获取道具GetProfile,但收到消息
元素类型无效:预期为字符串(对于内置组件) 或类/函数(用于复合组件),但得到:未定义。您 可能忘记了从定义的文件中导出组件, 否则您可能混淆了默认导入和命名导入。
class GetProfile extends React.Component{
....
render(){
return(
<div>
{React.cloneElement(this.props.children, {
data: this.state.data,
department : this.state.department
})
}
</div>
)
}
}
export default GetProfile;
在Router.js中,这是我的代码
import Home from './components/Home';
import GetProfile from './action/GetProfile';
....
<GetProfile>
<Authenticated exact path="/home" render={(props) => <Home {...props.data}/>}/>
</GetProfile>
....
答案 0 :(得分:1)
try by importing React
import React from 'react'
class GetProfile extends React.Component{
....
render(){
return(
<div>
{React.cloneElement(this.props.children, {
data: this.state.data,
department : this.state.department
})
}
</div>
)
}
}
export default GetProfile;