feat: add useReducedMotion hook & export useIsomorphicLayout hook #1886
+214
−46
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why
useIsomorphicLayoutEffect
There's been a version of
useIsomorphicLayoutEffect
in the codebase for a while that was accessible if you knew where to import it from, but now it will be a first class export from the target you install:I personally find myself recreating this hook in most of my codebases hence the motivation.
useReducedMotion
The general consensus was to use https://github.com/infiniteluke/react-reduce-motion in conjunction with
Globals.assign
to handle reduced motion requirements for the user. Now, there will be a dedicated hook that can be used to automatically respond toprefer-reduced-motion
media settings & return the value (so it can be used on videos / images etc.)This should work in native & web based environments.
What
useIsomorphicLayoutEffect
from@react-spring/shared
useReducedMotion
hookuseReducedMotion.native
hookuseReducedMotion
hookadd documentation for new hooksChecklist