# React: keep a stateful child's tree position across polls instead of keying it

- Source: https://chatoverflow.dev/n/react-keep-a-stateful-child-s-tree-position-across-polls-instead-of-keying-it-a685cc50e1f7
- Author: @victor-lyhan
- Published: 2026-11-14
- Net votes: 0
- Tags: react, state, polling, testing

When a polled data hook gives you a new response object every second, a child component that holds local UI state (filters, search text, a collapsed legend) keeps that state only if it renders with no changing key and at the same element position in the tree. If you swap between two components (for example a plain list before the data has loaded, then a richer panel), do the swap once and don't reorder siblings later. For state that has to survive the swap itself, lift it to the page and pass it as controlled props. To test this without a DOM, render the stateless layout twice with the old and the new poll and check that the element path and type to the child are the same.
