reactjs,将道具从一个组件发送到另一个组件
我想把道具从组件A发送到组件B。我怎么做? 顺便说一下,我正在使用reactjs,将道具从一个组件发送到另一个组件,reactjs,Reactjs,我想把道具从组件A发送到组件B。我怎么做? 顺便说一下,我正在使用react.lazy() 在这种情况下,我从不使用React.lazy。但我可以给你一个建议。 使用HOC传递道具。 创建HOC: const LazyHOC = ({ component: Component, ...rest }) => ( <Suspense fallback={...}> <Component {...rest} /> </
react.lazy()
在这种情况下,我从不使用React.lazy。但我可以给你一个建议。 使用HOC传递道具。 创建HOC:
const LazyHOC = ({ component: Component, ...rest }) => (
<Suspense fallback={...}>
<Component {...rest} />
</Suspense>
)
使用HOC包装组件:
const LazyCustomerList = props => <LazyHOC component={CustomerList} {...props}/>
const LazyCustomerDebt = props => <LazyHOC component={CustomerDebt} {...props}/>
const LazyCustomerList=props=>
const LazyCustomerDebt=props=>
你可以传递这样的道具:
const routes = [
{ path: '/', exact: true, name: 'Home page' },
{ path: '/customerlist', name: 'Debt list', component: <LazyCustomerList props={...} />},
{ path: '/customerdebt', name: 'Customer Debt', component: <LazyCustomerDebt />},
const路由=[
{路径:'/',精确:true,名称:'主页'},
{路径:'/customerlist',名称:'债务清单',组件:},
{路径:'/customerdebt',名称:'客户债务',组件:},
到目前为止您尝试了什么?网上有很多相关资料。
const LazyCustomerList = props => <LazyHOC component={CustomerList} {...props}/>
const LazyCustomerDebt = props => <LazyHOC component={CustomerDebt} {...props}/>
const routes = [
{ path: '/', exact: true, name: 'Home page' },
{ path: '/customerlist', name: 'Debt list', component: <LazyCustomerList props={...} />},
{ path: '/customerdebt', name: 'Customer Debt', component: <LazyCustomerDebt />},