React props vs children . What to use when?

后端 未结 5 504
伪装坚强ぢ
伪装坚强ぢ 2021-01-12 05:50

What is the difference between the two approaches ?

Passing text for a button as props

   

    function TextCo         


        
5条回答
  •  情深已故
    2021-01-12 06:06

    You should use children when you don't know them ahead of time, see: https://reactjs.org/docs/composition-vs-inheritance.html

    Here, if you KNOW that you'll use a title inside your child component, just use a named prop.

    I'd say that if you ask yourself the question: "Ok, but what will that generic component render?" is when you should use children

提交回复
热议问题