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

--

--

Acid Coder

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