DEV Community

Discussion on: A Clean Way to Conditionally Render Components

 
anxiny profile image
Anxiny

Yes, the statement in <If/> will be evaluated, but I feel it is minor problem that can be avoid, for example, enclosing the statement inside the child component.

Thanks for point this out!

Thread Thread
 
lukaselmer profile image
Lukas Elmer • Edited

Beside the performance issue, this can be an issue if you check in the condition a precondition for the rendering (e.g. if an object exists), and in the rendering part you depend on this check (e.g. access properties of this object).

E.g. let post: Post | undefined
Check in the condition if post !== undefined
Render post.title if the condition is true