MotionWrapper.js 949 B

1234567891011121314151617181920212223242526272829
  1. "use client";
  2. import * as React from 'react';
  3. import { Provider as MotionProvider } from 'rc-motion';
  4. import { useToken } from '../theme/internal';
  5. const MotionCacheContext = /*#__PURE__*/React.createContext(true);
  6. if (process.env.NODE_ENV !== 'production') {
  7. MotionCacheContext.displayName = 'MotionCacheContext';
  8. }
  9. export default function MotionWrapper(props) {
  10. const parentMotion = React.useContext(MotionCacheContext);
  11. const {
  12. children
  13. } = props;
  14. const [, token] = useToken();
  15. const {
  16. motion
  17. } = token;
  18. const needWrapMotionProviderRef = React.useRef(false);
  19. needWrapMotionProviderRef.current || (needWrapMotionProviderRef.current = parentMotion !== motion);
  20. if (needWrapMotionProviderRef.current) {
  21. return /*#__PURE__*/React.createElement(MotionCacheContext.Provider, {
  22. value: motion
  23. }, /*#__PURE__*/React.createElement(MotionProvider, {
  24. motion: motion
  25. }, children));
  26. }
  27. return children;
  28. }