Search code examples
javascriptreactjsreact-nativestatestateless

Stateful and Functional stateless components


How to convert Stateless functional components to stateful component in order to use lifecycle methods and passing props to it like Stateless Component.

( export default JobCard = (props) => { 
   ............
 }
)

I need to convert this to stateful component in order to use life-cycle method and pass props to the return function like how props is passed here. Thank you in advance.


Solution

  • You can do it like this:

    export default class JobCard extends React.Component {
      render() {
    
        // here you can access props passing down from
        // parent components like: this.props
    
        return (
          <div>
            Hi, I'm a super smart component!
          </div>
        );
      }
    }