DEV Community

Discussion on: React's render() Doesn't... Render

Collapse
 
louy2 profile image
Yufan Lou

Calling render() doesn't necessarily return anything.

It returns a virtual DOM. That's its whole contract. It doesn't return a virtual DOM only within the React framework, if you call it you would get a virtual DOM.

Exactly how often will render() be called, anyway?

You can measure it if you really want to know. It may be useful for optimization sometimes. It is a form of lazy evaluation, so it is more difficult to reason it out, but not impossible.

Although this is somewhat semantic, "render" doesn't really describe what the render() function is actually doing.

You're going directly against this quote:

It is important to remember that the reconciliation algorithm is an implementation detail. React could rerender the whole app on every action; the end result would be the same. [emphasis edited]

You don't see people using allocateAndCopyConcatenate(String s1, String s2) in Java, although that's what the + operator does. (FYI: In Java, don't use + to build new Strings in a loop, use a StringBuilder.)

Remembering exactly what optimizations React uses doesn't help your own optimization. Profile, profile, profile.