Acid Coder
1 min readJan 16, 2020

--

you can actually write for loop in render, but you need to do it outside of return

the reason for this is, return and jsx only accept expression,

which mean you need to have something like this

<A>{must be an expression}</A>

what is expression? an expression is value or statement that can be evaluated into value, since for loop cannot be evaluated into value, hence error

however map or forEach can be evaluated into value (forEach can only evaluate into undefined btw), you can write map or forEach in jsx

the same reason why you cannot do if else in jsx but you can do ternary operator, because if else cannot evaluate in value while ternary can

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Acid Coder
Acid Coder

Written by Acid Coder

Typescript Zombie. Youtube Pikachu On Acid. (Unrelated to programming but by watching it you become a good developer overnight)

No responses yet

Write a response