How to write if statement in react js tutorial for beginners

preview_player
Показать описание
Today we'll talk about how to write if statement in react js.

Of course, if we think about if statement in Javascript or Typescript logic, it's the same as in every Javascript or Typescript place.

It's just if/else like pure javascript, but in this case, we won't talk about the normal if/else.

In react, we'll need if statements for the one more thing, it's the rendering.

It's named "Conditional rendering", but to make it simple, let's stay with "if statement in react".

The first way that we can use is to define the conditional rendering directly in the components layout.

It's quick and easy that we'll use the most, and in some cases, it is the best for performance.

We'll be using this way in the cases when we have only one condition, more just as "if", when we would like to render some element when a specified condition is passed.

The second way is the function created to handle specified parts of the layout, and render it conditionally, to do that we can use not only if/else but the switch case as well.

This one way is right to use in cases where we have more conditions, especially the 1 with switch one.

But it fires the function anyway, so it is no sense to use it when we have one condition.

Remember to SUBSCRIBE to our channel for more programming content!

For the written article and code example VISIT US here:

MEET US:

#reactjs #conditionalrendering #ifelse
Рекомендации по теме
Комментарии
Автор

hello sir is the golang tuturial stoped ?

khebchiabdallah