Ads Top

How can use props in react?

Props in react:

We can use props in simply three ways one is direct with {props.propertyName} , second as object and third is as destructuring method. As you can understand with below code:


export default (props) => {

  return (

    <div className="section-title">

      <h2>{props.heading2}</h2>

      <p>{props.paragraph}</p>

    </div>

  )

}

  

export default ({heading2,paragraph}) => {

  return (

    <div className="section-title">

      <h2>{heading2}</h2>

      <p>{paragraph}</p>

    </div>

  )

}

 

export default (props) => {

  // destructring 

  const {heading2,paragraph} = props;

  return (

    <div className="section-title">

      <h2>{heading2}</h2>

      <p>{paragraph}</p>

    </div>

  )

}


 We use props with any react component.




No comments:

Copyright Reserved to Anything Learn. Powered by Blogger.