Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Deprecate and remove useFocusZone dependency array #5450

Open
iansan5653 opened this issue Dec 16, 2024 · 1 comment
Open

Deprecate and remove useFocusZone dependency array #5450

iansan5653 opened this issue Dec 16, 2024 · 1 comment
Labels
enhancement New feature or request react

Comments

@iansan5653
Copy link
Contributor

useFocusZone accepts an uncommon optional second argument: an array of dependencies. While comparable to the dependency arrays passed to other React hooks, the optionality and unlinted nature of this argument make it easy to forget about or incorrectly configure. I have personally introduced a few bugs because I didn't know this argument needed to be considered.

I think with modern JavaScript this array is probably wholly unnecessary. All options passed to useFocusZone through the options object can easily be included as dependencies by using a shallow comparison. The trickier part is for the hook to know when the contents of the container element change, but this can now relatively easily be achieved by using a MutationObserver on the parent.

With MutationObserver, the dependencies array could be totally removed. This would simplify the API and clear up a potential footgun.

@lesliecdubs lesliecdubs added the enhancement New feature or request label Dec 17, 2024
@lesliecdubs
Copy link
Member

Thanks for filing, @iansan5653! Things are a bit quiet though the holidays, so I'm going to leave this in the Primer inbox to discuss with the team in the new year to see how we might be able to move this forward.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request react
Projects
None yet
Development

No branches or pull requests

2 participants