EasyReact Fundamentals📖 Theory Question

What is React and what problem does it solve?

💡

Hint

Declarative UI library — describe what the UI should look like, not how to update it

Full Answer

React is a JavaScript library for building user interfaces. It solves the problem of keeping the UI in sync with application state.

Core ideas:

  • Declarative — you describe the desired UI for a given state; React figures out DOM updates
  • Component-based — split UI into reusable, self-contained pieces
  • Virtual DOM — React maintains a lightweight copy of the DOM, diffs it on state change, and batches minimal real DOM updates
  • Unidirectional data flow — data flows down (props), events flow up (callbacks)

// Imperative (jQuery style) — how to update
const btn = document.getElementById('btn');
btn.addEventListener('click', () => {
  const count = parseInt(btn.textContent) + 1;
  btn.textContent = count;
});

// Declarative (React style) — what it should look like
function Counter() {
  const [count, setCount] = useState(0);
  return <button onClick={() => setCount(c => c + 1)}>{count}</button>;
}
💡 React's real innovation was making UI a pure function of state: UI = f(state). Any time state changes, React re-runs the function and reconciles the difference.

Practice this in a timed sprint →

5 free questions, no signup required

⚡ Start Sprint