在没有 props 参数的情况下访问函数组件中的子组件

发布于 2025-01-17 23:00:43 字数 382 浏览 3 评论 0原文

我创建了一个如下所示的类:

const Button = ({href, className, rippleColor, type}) => {
... 
}

我正在使用这样的组件:

<Button rippleColor={'#ff0000'} type={'primary'} className={'my-4'}>Test</Button>

现在我想访问组件的 props.children 而不切换 ({href, className,rippleColor, type})(props)

有办法做到这一点吗?

i've created a class that looks like this:

const Button = ({href, className, rippleColor, type}) => {
... 
}

i'm using the component like this:

<Button rippleColor={'#ff0000'} type={'primary'} className={'my-4'}>Test</Button>

now i want to get access to the props.children of the component without switching ({href, className, rippleColor, type}) to (props)

is there a way to do this?

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

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

发布评论

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

评论(1

北陌 2025-01-24 23:00:43

是的,只需将 children 添加到您的解构中,

const Button = ({children, href, className, rippleColor, type}) => {
... 
}

Yes, simply add children to your destructuring,

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