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

feat: add useReducedMotion hook & export useIsomorphicLayout hook #1886

Merged
merged 7 commits into from
Jul 13, 2022

Conversation

joshuaellis
Copy link
Member

@joshuaellis joshuaellis commented May 5, 2022

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:

import { useIsomorphicLayoutEffect } from '@react-spring/web'

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 to prefer-reduced-motion media settings & return the value (so it can be used on videos / images etc.)

// web based
import { useReducedMotion } from '@react-spring/web'
// native based
import { useReducedMotion } from '@react-spring/native'

This should work in native & web based environments.

What

  • export useIsomorphicLayoutEffect from @react-spring/shared
  • add useReducedMotion hook
  • add useReducedMotion.native hook
  • add tests for useReducedMotion hook
  • add documentation for new hooks

Checklist

  • Documentation updated
  • Ready to be merged

@vercel
Copy link

vercel bot commented May 5, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
react-spring-io ✅ Ready (Inspect) Visit Preview Jul 13, 2022 at 7:50AM (UTC)

@codesandbox-ci
Copy link

codesandbox-ci bot commented May 5, 2022

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit a9f5862:

Sandbox Source
spring-animating-auto Configuration
spring-card Configuration
spring-cards-stack Configuration
spring-chain Configuration
spring-draggable-list Configuration
spring-exit-before-enter Configuration

@joshuaellis joshuaellis marked this pull request as ready for review July 13, 2022 07:48
@joshuaellis joshuaellis changed the title [feat]: add useReducedMotion hook & export useIsomorphicLayout hook feat: add useReducedMotion hook & export useIsomorphicLayout hook Jul 13, 2022
@joshuaellis joshuaellis merged commit 3365cea into master Jul 13, 2022
@joshuaellis joshuaellis deleted the feat/isomorphic-effect-and-reduce-motion branch July 13, 2022 07:52
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