Using passed in props in react class methods

twitter logo github logo Updated on ・1 min read

To make use of a prop, passed in or down from a parent component. You first created a constructor for the class. Check the code below:

class SomeClass extends Component {
   Constructor(props) {
       super(props);
       this.props = props; 
   }

   someMethod = () => {
       console.log(this.props)
   }
}

Weird! Thought it will happen some other way.

twitter logo DISCUSS (1)
markdown guide
 

Hi Oyeyipo.

Weird! Thought it will happen some other way.

Which part would you find weird & unintuitve?

Classic DEV Post from Oct 16

Playing with easter eggs: Ideas for making your website more fun

Oyeyipo Olawale profile image
Nothing really matters
Join dev.to

Better understand your code.