Skip to main content
Journey Uncommon Logo
JourneyUncommon
mediumReactderived vs stored stateSingle-choice MCQ

A search component receives a `query` prop. To 'reset' an internal `selectedIndex` to 0 whenever `query` changes, which approach is the React-recommended way to handle this 'adjust state when a prop changes' case for a value that is otherwise genuinely local state?

// query is a prop; selectedIndex is local state that the user can change