B
B
bormor2018-03-11 13:32:10
JavaScript
bormor, 2018-03-11 13:32:10

Declaring an event handler in React via simplified syntax - what does this line of code do? How to google details about it?

I'm learning react. Found a convenient option for declaring an event handler.
(without using constructor and bind).

handleClick = (event) =>{
    ...
};

What is it?
Reminds function expression through function arrow. But there is no const.
Is this a new JS feature? Or the magic of React?
How to google details about it?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
K
kn1ght_t, 2018-03-11
@bormor

it's just a class field that an arrow function is assigned to, the
arrow function doesn't have its own context, so you don't have to explicitly bind the context in the constructor,
it's just handy when you use something with "this" in methods, like this:
this.setState({...});

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question