Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ReactJS bind method to class component

Im doing ReactJS course in Codeacademny and they confused me.

(EDIT - full code) Photo of the code :

Code

and there's no constructor or anywhere call to any bind method for the scream class method.

However in further exercises they tell you can't do that.

I probably miss something.

like image 365
Trigosin Darom Avatar asked Nov 19 '19 12:11

Trigosin Darom


People also ask

What is Bind method in React JS?

The bind() is an inbuilt method in React that is used to pass the data as an argument to the function of a class based component.

How do you call a method from another class React?

To call a method from another class component in React. js, we can pass the class method as a prop to a child component. We have components Class1 and Class2 . And Class1 is a child of Class2 .


1 Answers

Apparently this.scream is an arrow function. Arrow function does not require binding. It points to the right context by default.

scream = () => { ... }
like image 126
kind user Avatar answered Nov 04 '22 20:11

kind user