React Conditional Rendering Best Practice

preview_player
Показать описание
The exception to this practice is if you have a spinner component, or something similar, that you know for sure lives within your codebase, then you use something like this:
{loading && "spinner component goes here" }

0:00 - Intro - how JavaScript "short circuiting" can cause difficult to detect errors in React conditional rendering
0:24 - Undetected error condition due to JavaScript "falsey" values
2:26 - Official ReactJS documentation regarding conditional rendering in React
3:55 - Better alternatives to "short circuiting" for React conditional rendering
4:41 - Computer programming best practices

Avoid using the logical AND (&&) operator, also known as "short circuiting" for React conditional rendering, instead use the ternary operator or standard if/else conditional flow for clarity.

ReactJS Tutorial.
Рекомендации по теме
Комментарии
Автор

My friends: The exception to this practice is if you have a spinner component, or something similar, that you know for sure lives within your codebase and will render correctly, then you use something like this:
{loading && <Spinner /> }

Huy_Nguyen_USA
Автор

I like the way you think about programming.

AllTheWorldAStage
Автор

Good call, thanks. How did you get those icons to show up?

triplel