简体   繁体   English

反应重组通行证道具

[英]React recompose pass props

For example, we have a container <ContainerName data=someData> and pass some props data . 例如,我们有一个容器<ContainerName data=someData>并传递了一些props data

In this container we use recompose and have the following code: 在此容器中,我们使用recompose并具有以下代码:

const enhance = compose(
      withProps({
        statuses: ['ordered', 'received'],
      }),
      withProps(
        // how do I pass props from this container to component ?
      ),
      withState('error', 'setError', false),
      withState('successAdded', 'setSuccessAdded', false),
      withState('loading', 'setLoading', false),
      withState('confirmModal', 'setConfirmModal', false),
...
export default enhance(ComponentForm);

How do we pass the props which belong to this container to our component ? 我们如何将属于此容器的道具传递给组件?

A component does not need to declare all the props it will receive via recompose HOCs to be able to use it (unless your are explicitly omitting props in your compose function via mapProps). 组件无需声明将通过重组HOC接收到的所有道具就可以使用它(除非您通过mapProps明确在compose函数中省略了道具)。

Pass the data as you would with a normal component, and have your child component use it as it would any normal prop 像使用常规组件一样传递数据,并让您的子组件像使用任何常规道具一样使用它

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM