您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DialogTransition.tsx 896B

12345678910111213141516171819202122232425262728
  1. import React, { ReactElement, useEffect, useState } from 'react';
  2. export const DialogTransitionContext = React.createContext({ isUnmounting: false });
  3. const DialogTransition = ({ children }: { children: ReactElement | null; }) => {
  4. const [ childrenToRender, setChildrenToRender ] = useState(children);
  5. const [ isUnmounting, setIsUnmounting ] = useState(false);
  6. useEffect(() => {
  7. if (children === null) {
  8. setIsUnmounting(true);
  9. setTimeout(() => {
  10. setChildrenToRender(children);
  11. setIsUnmounting(false);
  12. }, 150);
  13. } else {
  14. setChildrenToRender(children);
  15. }
  16. }, [ children ]);
  17. return (
  18. <DialogTransitionContext.Provider value = {{ isUnmounting }}>
  19. {childrenToRender}
  20. </DialogTransitionContext.Provider>
  21. );
  22. };
  23. export default DialogTransition;