Frontend3 min read

React: a filtered list does not need an Effect

Keep the search query in state and derive the results during rendering to avoid a second synchronization problem.

Written by Rajaram Lavudya November 15, 2026

Keep the source of truth small

A searchable project list has two inputs: projects and a search query. The visible list follows from those inputs. Saving that list in another state variable creates a second value to keep synchronized. Calculate it during rendering instead of scheduling an Effect that writes the filtered result back into state.

Express the relationship directly

Store the editable query; calculate the results. When the inputs change, rendering calculates the new list. If filtering becomes measurably expensive, consider memoization as a performance tool rather than a requirement for correctness.

const [query, setQuery] = useState('');
const normalized = query.trim().toLowerCase();
const visible = projects.filter(project =>
  project.title.toLowerCase().includes(normalized)
);

Use Effects for synchronization

Effects are useful when a component must synchronize with an external system. Deriving a local list is different from subscribing to an external source. Before adding an Effect, identify the system being synchronized. If all the information already exists in props and state, a calculation may be enough.

Walk through a change in the data

Consider a portfolio with an active search query and a category filter. A project title changes after new data arrives. If the visible list is independently stored in state, every update path must remember to refresh that list. When the list is calculated from the current inputs, the same relationship handles the renamed project automatically. Write the relationship as a pure function and try it with an empty query, mixed case, and an empty collection before connecting the UI. Keep the original project objects unchanged.

Compose filters without hidden updates

Apply text and category conditions to the same source collection. Normalize the query once so the predicate remains readable. For a tiny portfolio this calculation is typically simple enough to inspect directly. When the dataset becomes large, measure the interaction before introducing memoization or moving filtering to a server. The user-facing behavior should remain the same through that optimization: the count matches the displayed results, the empty state explains what happened, and clearing the input restores the expected collection.

const visible = projects.filter(project => {
  const matchesQuery = project.title
    .toLowerCase().includes(normalized);
  const matchesCategory = category === 'all' ||
    project.category === category;
  return matchesQuery && matchesCategory;
});

Separate local filtering from fetching

Filtering a collection already in memory is not the same task as requesting remote search results. For remote search, define loading and error states, and decide how stale responses should be handled when someone types quickly. Keep that network concern separate from the local predicate. To review the local version, replace the project collection while keeping the search box populated and verify that the screen reflects the new data immediately. Then check keyboard focus and the empty state; a clean state model should support a clean interaction.