Reactjs 导入函数react组件时出错
我在react中有一个函数componet,它得到了以下一些道具:Reactjs 导入函数react组件时出错,reactjs,Reactjs,我在react中有一个函数componet,它得到了以下一些道具: 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 [
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>
当我更改为component={ThermoBreastCanCorpage}时,我不会得到任何错误,但我必须以某种方式传递道具。我还没有反应过来,不知道我哪里做错了?你可以试着改变这一点
对此
您可以尝试更改此设置
对此
Ciao,要在
路线中的组件上传递道具
组件
您必须以以下方式使用箭头功能:
<Route path="/thermo-breast-cancer" component={() => <ThermoBreastCancerPage is_logged_in='false' fname='' lname='' />} />
}/>
Ciao,要在路线中的组件上传递道具
组件
您必须以以下方式使用箭头功能:
<Route path="/thermo-breast-cancer" component={() => <ThermoBreastCancerPage is_logged_in='false' fname='' lname='' />} />
}/>
您应该直接从状态使用值,而不是将道具传递给组件。我想传递初始状态值,所以我使用了道具。您应该直接从状态使用值,而不是将道具传递给组件。我想传递初始状态值,所以我使用了道具。在中呈现组件有几种方法,他们三人都得到了相同的道具(尽管他们的行为略有不同)。您可以在这里了解更多关于它们的信息:有几种方法可以渲染
中的组件,并且这三种组件都获得相同的道具(尽管它们的行为略有不同)。您可以在这里阅读更多关于它们的信息:如果您希望将路由道具传递给用户,我想您应该在这里使用render={..}
而不是component={…}
component@Shadab是的,您可以像使用render={(props)=>…}
一样使用render,但也可以使用带有箭头函数的组件={..}
如果希望将路由道具传递给component@Shadab是的,您可以像render={(props)=>…}
一样使用渲染,但也可以使用带有箭头函数的组件。