reactjs - 导入函数反应组件时出错
问题描述
我在反应中有一个函数组件,它得到一些道具如下:
export default function ThermoBreastCancerIntroPage(props) {
console.log('rest is logged in is')
console.log(props.is_logged_in);
const [is_logged_in, set_is_logged_in] = useState(props.is_looged_in);
const [fname, set_fname] = useState(props.fname);
const [lname, set_lname] = useState(props.lname);
在我的 index.js 中,我导入它然后想使用它
import ThermoBreastCancerPage from "views/LandingPage/ThermoBreastCancerPage.js";
ReactDOM.render(
<Router history={hist}>
<Switch>
<Route path="/thermo-breast-cancer" component={<ThermoBreastCancerPage is_logged_in='false' fname='' lname='' />} />
</Switch>
</Router>
但在上面,我得到了错误
Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
当我更改为 component={ThermoBreastCancerPage} 时,我不会收到任何错误,但我必须以某种方式传递道具。我是新手,不知道我做错了什么?
解决方案
你可以尝试改变这个
<Route path="/thermo-breast-cancer" component={<ThermoBreastCancerPage is_logged_in='false' fname='' lname='' />} />
对此
<Route path="/thermo-breast-cancer">
<ThermoBreastCancerPage is_logged_in='false' fname='' lname='' />
</Route>
推荐阅读
- ios - 我如何知道一种 UIColor 和另一种 UIColor 之间的百分比差异?
- angular - 如何在 Typescript 中生成两个随机数并检查两者是否相同?
- angular - AppModule 的 NgModule.imports 中位置 1 的值不是一个类
- python - Python解密文件的问题 - 类型错误
- python - 在 django 过滤器 filterset_fields 中设置值
- javascript - JavaScript 正确实现提交
- javascript - 如何更改 Material ui 自动完成中选项的字体大小?
- ubuntu-16.04 - AttributeError:模块“PySimpleGUI”没有属性“主题”
- python - 熊猫可以在没有任何警告的情况下截断我的数据并导致无法挽回的数据丢失吗?
- flutter - 飞镖中函数参数后的问号