当组件作为另一个组件的道具传递时,如何通过道具?

发布于 2025-02-07 05:21:42 字数 441 浏览 3 评论 0原文

我的组件如下:

const ArrowDownIcon = (name:string) => (
  <MaterialCommunityIcons
    name={name}
    size={50}
    color={theme.colors.text}
  />
);

然后,我应该将上述组件作为道具传递给以下组件:

const Dropdown = () =>{
  <DropDownPicker
    ArrowDownIconComponent={ArrowDownIcon}
  />
}

但是它不起作用,因为我应该将name的道具传递给arrowdowniconcomponent。有人可以向我解释一下该怎么做吗?

I have a component as follows:

const ArrowDownIcon = (name:string) => (
  <MaterialCommunityIcons
    name={name}
    size={50}
    color={theme.colors.text}
  />
);

Then I should pass the above component as a prop to the following component:

const Dropdown = () =>{
  <DropDownPicker
    ArrowDownIconComponent={ArrowDownIcon}
  />
}

But it doesn't work, since I should pass the prop of name to the ArrowDownIconComponent. Can somebody please explain me how to do this please?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦一生花开无言 2025-02-14 05:21:42

这里没有错,在下拉picker中,您只需要渲染arrowdowniconcomponent

const DropDownPicker = ({ArrowDownIconComponent}) => (
  ...
  <ArrowDownIconComponent />
  ...
)

您也可以使用这种方式使用

const Dropdown = () =>{
  <DropDownPicker
    arrowDownIconComponent={<ArrowDownIconComponent />}
  />
}


const DropDownPicker = ({arrowDownIconComponent}) => (
  ...
  { arrowDownIconComponent }
  ...
)

Nothing wrong here, in DropDownPicker you just have to render your ArrowDownIconComponent

const DropDownPicker = ({ArrowDownIconComponent}) => (
  ...
  <ArrowDownIconComponent />
  ...
)

You can also use it this way

const Dropdown = () =>{
  <DropDownPicker
    arrowDownIconComponent={<ArrowDownIconComponent />}
  />
}


const DropDownPicker = ({arrowDownIconComponent}) => (
  ...
  { arrowDownIconComponent }
  ...
)
躲猫猫 2025-02-14 05:21:42

您可以以这种方式将名称作为道具传递

<DropDownPicker
   ...
   ArrowDownIconComponent={() => <ArrowDownIconComponent name="box" />}
   ...
/>

you can pass the name as a prop in this way

<DropDownPicker
   ...
   ArrowDownIconComponent={() => <ArrowDownIconComponent name="box" />}
   ...
/>
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文