Web Technologies

What is React and how does it work?

What React is and how it works: components, state, JSX and declarative UI, and how React updates only the parts of the page that change, explained by cats.

  • 7 min read
  • 5 questions
  • +35 XP
Transcript

React, explained by cats. Kitty wants to build a webpage. Just one tiny button. How hard could it be? First version: HTML. CSS. A little JavaScript. Reasonable. Then Kitty wants the button to count clicks. Then show a message. Then hide the message.

Then change the color. Then update the cart. Chaos. So Kitty finds React. React breaks the page into components. Components are Tiny reusable pieces. Like a Button. Or a Navbar. Each component has state. State is just memory. Such as: “Button clicked 7 times.”.

When React sees the state change... it updates the screen. That’s the magic part. Kitty doesn’t rebuild the whole page. React figures out what changed, automatically. Cats call this declarative. Which means: Kitty says what the UI should look like, not every tiny step to redraw it.

React also uses JSX. JSX looks a lot like HTML, but it lives inside JavaScript. So Kitty can describe the UI right where the logic lives. At first, it feels weird. Then Kitty gets used to it. That’s React. A popular JavaScript library. To create interactive user interfaces.