ycliper

Популярное

Музыка Кино и Анимация Автомобили Животные Спорт Путешествия Игры Юмор

Интересные видео

2025 Сериалы Трейлеры Новости Как сделать Видеоуроки Diy своими руками

Топ запросов

смотреть а4 schoolboy runaway турецкий сериал смотреть мультфильмы эдисон
Скачать

Section 9 (React): Lesson 7 - Conditional Rendering

Автор: ximxim

Загружено: 2023-06-07

Просмотров: 4

Описание: Hey you and welcome.

In this video we will talk about conditional rendering and react.

So let's dive right into it.

What I want to do with my code right now, I'm in the app dot TSX component and I want to make it so

that we can press the something button.

And when you press it, something shows up underneath it like a paragraph could be here or it could

be a whole new component that we create, but something underneath it shows.

Let's just take away else button.

I will put these paragraphs under the button.

They don't really have to be under, just visually it looks a little bit more like something that I

would change.

So what I what I want to do is there's two paragraphs.

When I press on something, the first paragraph should show up, which is in black right now.

And if I press on, button something again, then the red one shows up, black one disappears.

So I'm showing one or the other when the toggle happens.

So how do we do that?

Well, we have to put all that we have learned so far about props and expand on that.

We also learned a little bit about events using onClick event in the previous video.

We need to expand on that as well.

And we also need to use use state to create a state on a global level.

So let me show you what I mean on the button.

When I press it, the toggle happens.

It has a local state, but I do want that state to be written on a global level.

So there's two ways to do it right?

Either I start using use state right here and notice what I'm doing here.

I'm instead of importing from React before like I did.

I could do that and I can start using it instead of doing that.

Oops.

I'm just going to start writing you state and notice that VS code is helping me out by saying do you

want to bring in use state from React library?

In this case, yes I do press enter and it will just auto import that for me.

If this functionality is not working for you out of the box, you may need an extension.

I will go to my extensions section in VS code and there is a auto import extension this one and you

can use that.

Let me hide that.

You can use this extension, install that and that may work better for you, but I believe vs code has

it built in.

All right, enough about that.

Let me close this out.

Command W and use state.

So I'm using use state up top in app dot TSX.

I can set this default to false and I can say is toggled.

Set is toggled.

And I can pass is toggled.

To button like so and then button.

If I go to jump to or go to definition for button, I can see.

Okay it's not letting me do that here.

Okay.

So if I go to definition for button TSX, I can accept it's toggled as a prop and then pass it down

and take away state.

So that means the component is no longer stateful.

That's one way to do it.

Right and valid way to do it.

There's no right or wrong way.

I just want to show you a different way that you may see as a pattern.

So I'm going to use a callback function.

I'll close out of this, go to app dot TSX and I will have a is toggled set is toggled state still in

app dot TSX.

We do need that and I want this to be changed every time the button is clicked.

So instead of me passing it a boolean type or a string type or object type, I'm going to pass a function

to it.

So let's first create our function.

This function has to be within the function that is the app component.

It has to be within.

You cannot just create it outside and pass it down.

I mean, that may be possible, but you're getting outside of the life cycle of React component.

We want to stay inside the life cycle in case the state changes your function to change accordingly.

Right?

So that's why we're inside the function component or sorry, the app component.

And I will start a new function called handle toggle equals to anonymous function or error function.

Start the curlies and whenever this get called is toggled should be set to something.

And we don't know what that is yet.

And what I will say is when handle toggle is called, whoever calls it, this should pass me the value,

which would be a type of boolean.

So colon boolean means type of boolean and this is the value, which is the actual value being passed

Не удается загрузить Youtube-плеер. Проверьте блокировку Youtube в вашей сети.
Повторяем попытку...
Section 9 (React): Lesson 7 - Conditional Rendering

Поделиться в:

Доступные форматы для скачивания:

Скачать видео

  • Информация по загрузке:

Скачать аудио

Похожие видео

Section 9 (React): Lesson 8 - useContext

Section 9 (React): Lesson 8 - useContext

Czarnek vs. Tusk: brutalna gra o głosy zakutych łbów | Salonik Polityczny Rafała Ziemkiewicza

Czarnek vs. Tusk: brutalna gra o głosy zakutych łbów | Salonik Polityczny Rafała Ziemkiewicza

The Most Advanced 3D Printer I’ve Ever Used

The Most Advanced 3D Printer I’ve Ever Used

Why I’m Deleting My Google Account in 2026 (And What I Use Instead)

Why I’m Deleting My Google Account in 2026 (And What I Use Instead)

The Bullsh** Benchmark

The Bullsh** Benchmark

Express Republiki 07.03.2026 | TV Republika

Express Republiki 07.03.2026 | TV Republika

PILNE! Reżim w rozsypce. Upadek Ajatollahów. Andrzej Gąsiorowski i Jan Piński LIVE 21

PILNE! Reżim w rozsypce. Upadek Ajatollahów. Andrzej Gąsiorowski i Jan Piński LIVE 21

Już nie ma odwrotu - wszyscy WRACAJĄ do silników spalinowych!

Już nie ma odwrotu - wszyscy WRACAJĄ do silników spalinowych!

Web Development Roadmap 2026 (No BS Guide!)

Web Development Roadmap 2026 (No BS Guide!)

I was a 10x engineer. Now I'm useless.

I was a 10x engineer. Now I'm useless.

Забудьте про Canva: Инфографика для урока в NotebookLM за 30 секунд

Забудьте про Canva: Инфографика для урока в NotebookLM за 30 секунд

Wojsko na węgierskich ulicach.

Wojsko na węgierskich ulicach. "Albo wynik, albo stan wyjątkowy"

YouTube CHANGED How Niches Work (+ Top Niche Ideas 2026)

YouTube CHANGED How Niches Work (+ Top Niche Ideas 2026)

Dlaczego strzelcy B-17 bali się wieży kulistej bardziej niż śmierci

Dlaczego strzelcy B-17 bali się wieży kulistej bardziej niż śmierci

Why Specialized Agents are Superior (How I Built an OpenClaw Superteam)

Why Specialized Agents are Superior (How I Built an OpenClaw Superteam)

GROK Показал AGI! Илон Маск ВЗОРВАЛ Индустрию ИИ! Grok СамоОбучается! Новый Уровень ИИ! В 100 РАЗ

GROK Показал AGI! Илон Маск ВЗОРВАЛ Индустрию ИИ! Grok СамоОбучается! Новый Уровень ИИ! В 100 РАЗ

7 ОШИБОК КАРЬЕРЫ: что мешает вашему росту на работе?

7 ОШИБОК КАРЬЕРЫ: что мешает вашему росту на работе?

Dlaczego TRUMP NIE WYGRA z IRANEM? STRATY dla ŚWIATA i WYBORY w USA #BizON

Dlaczego TRUMP NIE WYGRA z IRANEM? STRATY dla ŚWIATA i WYBORY w USA #BizON

Stanowski WYJAŚNIA Trzaskowskiemu! Czarnek na PREMIERA! Mazurek bez litości dla Tuska! Hity w sieci

Stanowski WYJAŚNIA Trzaskowskiemu! Czarnek na PREMIERA! Mazurek bez litości dla Tuska! Hity w sieci

Цифровой ошейник» для всей семьи: Как школьный мессенджер MAX собирает на вас досье?

Цифровой ошейник» для всей семьи: Как школьный мессенджер MAX собирает на вас досье?

© 2025 ycliper. Все права защищены.



  • Контакты
  • О нас
  • Политика конфиденциальности



Контакты для правообладателей: [email protected]