最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - React. Children as prop - Stack Overflow

programmeradmin0浏览0评论

I know how to pass children to React ponent:

<Button block
        href={url}
        target="_blank"
        bsStyle="primary"
        bsSize="xsmall">Open This Wonderful Link</Button>

But can I use this way:

<Button block
        href={url}
        target="_blank"
        bsStyle="primary"
        bsSize="xsmall" 
        children="Open This Wonderful Link" />

It works, but is this normal? Can I use this way every time?

P.S. Sorry for my poor English..)

I know how to pass children to React ponent:

<Button block
        href={url}
        target="_blank"
        bsStyle="primary"
        bsSize="xsmall">Open This Wonderful Link</Button>

But can I use this way:

<Button block
        href={url}
        target="_blank"
        bsStyle="primary"
        bsSize="xsmall" 
        children="Open This Wonderful Link" />

It works, but is this normal? Can I use this way every time?

P.S. Sorry for my poor English..)

Share Improve this question asked Apr 28, 2017 at 12:03 Виталий ЗаславскийВиталий Заславский 2492 silver badges11 bronze badges 4
  • You wont to pass react elem to ponent in some props, or you wont to use exactly "children" prop? – Sergey Orlov Commented Apr 28, 2017 at 12:08
  • I want to pass children as property in JSX element. In some cases it is more convenient. @SergeyOrlov, are you Russian? – Виталий Заславский Commented Apr 28, 2017 at 12:11
  • You can pass children as props. But you also can pass ponent as other props someName= {ponents} and then use them this.props.someName. – Sergey Orlov Commented Apr 28, 2017 at 12:19
  • Yes this is not only normal but expected. – InfiniteStack Commented Apr 28, 2017 at 13:04
Add a ment  | 

1 Answer 1

Reset to default 6

Yes, children is like any other prop and can be used as a prop to render child ponents, instead of nesting child ponents in the respective element

发布评论

评论列表(0)

  1. 暂无评论