Passing/Accessing props in stateless child component

后端 未结 8 2017
南方客
南方客 2020-12-05 10:04

I know you can pass all a react components props to it\'s child component like this:

const ParentComponent = () => (
   

Parent

8条回答
  •  不知归路
    2020-12-05 10:57

    When you write

    const ChildComponent = ({ someProp }) => (
       

    Child Component {someProp}

    )

    From all the props that you are passing to the childComponent you are just destructuring to get only someProp. If the number of props that you want to use in ChildComponents are countable(few) amongst the total number of props that are available, destructuring is a good option as it provides better readability.

    Suppose you want to access all the props in the child component then you need not use {} around the argument and then you can use it like props.someProp

    const ChildComponent = (props) => (
       

    Child Component {props.someProp}

    )

提交回复
热议问题