V
V
Vitaly the Wise2018-08-31 15:02:13
JavaScript
Vitaly the Wise, 2018-08-31 15:02:13

What are the restrictions on using the render method as an arrow function in React?

Good day. I recently started learning React and after some thought I decided to replace the construct

render() {
return (<h1>Hello World</h1>)
}

on the
render = () => (
<h1>Hello World</h1>)
);

But while reading the official React documentation and articles by experienced developers, I have not seen such use. Maybe in this approach there are some pitfalls that I do not see. I would be glad to help in this matter. Thanks in advance

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Anton Spirin, 2018-08-31
@tapinambur0508

after some thought, I decided to replace the design

You don't have to do that. Never use class properties for functions when a method can be dispensed with.
Example: If the render method is defined in the SomeComponent component, then for each instance it will be called from the prototype. If it is a property, then together with the instances you will create 1000 copies of the same function.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question