← React Beginner Questions - Set 6 Q53

What is the role of React Fiber?

React Beginner Questions - Set 6

Fiber is the rewrite of the reconciler that made rendering interruptible. You meet it through concurrent features, not through an API.

Example

import { useState, useTransition } from 'react';

export default function Search({ rows }) {
  const [query, setQuery] = useState('');
  const [results, setResults] = useState(rows);
  const [isPending, startTransition] = useTransition();

  function onChange(e) {
    const value = e.target.value;
    setQuery(value);                 // urgent: keep the input responsive
    startTransition(() => {          // interruptible: can be discarded
      setResults(rows.filter(r => r.name.includes(value)));
    });
  }

  return (
    <>
      <input value={query} onChange={onChange} />
      {isPending && <p>Filtering…</p>}
      <ul>{results.slice(0, 50).map(r => <li key={r.id}>{r.name}</li>)}</ul>
    </>
  );
}

What to notice

← Back to the question list