Skip to content

refactor: remove derived state useEffects from Carousel and Disclosure#183

Open
vass-k wants to merge 1 commit intoibelick:mainfrom
vass-k:refactor/controlled-state-sync
Open

refactor: remove derived state useEffects from Carousel and Disclosure#183
vass-k wants to merge 1 commit intoibelick:mainfrom
vass-k:refactor/controlled-state-sync

Conversation

@vass-k
Copy link
Copy Markdown
Contributor

@vass-k vass-k commented Mar 21, 2026

What changed?

This PR refactors the internal state management for the <Carousel> and <Disclosure> components to fix the Derived state in useEffect warnings flagged by React Doctor.

Both components previously relied on a useEffect to sync external prop changes into duplicated local state, which is an anti-pattern that causes unnecessary double-rendering.

How it improves the components

  1. Performance: Eliminating the useEffect syncs removes the sluggish double-render cycle entirely. When a controlled value changes, the component now updates the UI in a single pass.
  2. Correctness: Both components now implement the standard React "Controlled vs. Uncontrolled" pattern correctly. If the parent provides a value, the internal state machine defers entirely to the parent (isControlled).
  3. Clean Logs: The React Doctor warnings (compute during render instead) are fully resolved.

User Impact

None. The public API for both components is completely unchanged. No documentation updates are required, and existing usages of <Carousel> and <Disclosure> will automatically benefit from the cleaner rendering cycle.

- Removed redundant `useEffect` hooks used for state syncing
- Refactored [Carousel] to pass the correct active index down to the provider, eliminating duplicated state.
- Refactored [Disclosure] to properly handle controlled and uncontrolled modes using an `isControlled` check during render.
- Zero changes to the public API; all existing consumption works exactly the same.
@vercel
Copy link
Copy Markdown
Contributor

vercel bot commented Mar 21, 2026

@vass-k is attempting to deploy a commit to the julienthibeaut's projects Team on Vercel.

A member of the Team first needs to authorize it.

@vass-k vass-k marked this pull request as ready for review March 21, 2026 15:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant