The most popular UI framework.
Please read:
- Quick Start from Facebook.
- Thinking in React from Facebook.
- Describing the UI from Facebook.
- Adding Interactivity from Facebook.
- Using TypeScript from Facebook.
- Tutorial: Tic-Tac-Toe from Facebook.
- React is the most widely used and highly liked UI framework:
- React is in active development with a friendly community
- As a library, React composes well with other technologies
- React scheduling easier (for me) to reason about than event streams and signals
- A component is a top-level function that returns a React element
- Keep components pure:
- only change local variables
- same output for same input
- Nest components
- JSX: syntax to create React elements
- shorthand for
React.createElement()
className
(instead of HTMLclass
attribute)- Embed JavaScript between
{
and}
- shorthand for
- Conditional rendering
- Iterated rendering with the
key
attribute - Attaching event handlers
- useState
- subscription: trigger re-rendering when state changes
- state doesn't actually change until next re-render
- Use object/array spread operator
...
to change state partially
- A parent component can pass props to a child component
- Keep state in high level components, but not higher than needed
- Pass state down to sub-components as props, to read state
- Pass state change handler down to sub-components, to change state
- Child elements as props
- In React, rendering means calling components to produce React elements
- State updates request a re-render of component and children
- After rendering, React will commit only the changed elements to the DOM
- Browser will then paint those changes in the DOM