From 5572029a750c4a7a5a593b82b2ca8b76443f71bf Mon Sep 17 00:00:00 2001 From: yehuozhili <673632758@qq.com> Date: Thu, 9 Jul 2020 14:46:03 +0800 Subject: [PATCH] fix(transition): may cause wranning in strict mode --- src/components/Alert/alert.tsx | 14 ++++++++++-- src/components/Carousel/carousel.tsx | 10 +++++++-- src/components/Menu/submenu.tsx | 12 +++++++--- src/components/Modal/modal.tsx | 7 +++++- src/components/Select/select.tsx | 5 +++-- .../Transition/transition.stories.mdx | 22 +++++++++++++++---- src/components/Transition/transition.tsx | 3 +-- 7 files changed, 57 insertions(+), 16 deletions(-) diff --git a/src/components/Alert/alert.tsx b/src/components/Alert/alert.tsx index 697350c..7f19b9e 100644 --- a/src/components/Alert/alert.tsx +++ b/src/components/Alert/alert.tsx @@ -1,4 +1,12 @@ -import React, { FC, useState, useEffect, ReactNode, CSSProperties, DOMAttributes } from "react"; +import React, { + FC, + useState, + useEffect, + ReactNode, + CSSProperties, + DOMAttributes, + useRef +} from "react"; import classNames from "classnames"; import Button from "../Button"; import Icon from "../Icon"; @@ -76,6 +84,7 @@ export const Alert: FC = function(props: AlertProps) { `bigbear-alert-${type}`, className ? className : "" ); + const nodeRef = useRef(null); const [state, setState] = useState(!initAnimate); useEffect(() => { if (initAnimate) { @@ -97,8 +106,9 @@ export const Alert: FC = function(props: AlertProps) { classNames={animateClassName ? animateClassName : ""} timeout={timeout!} wrapper={wrapper} + nodeRef={nodeRef} > -
+
{icon && icon} {title} diff --git a/src/components/Carousel/carousel.tsx b/src/components/Carousel/carousel.tsx index 6474ef9..953a4c9 100644 --- a/src/components/Carousel/carousel.tsx +++ b/src/components/Carousel/carousel.tsx @@ -139,14 +139,19 @@ function Carousel(props: PropsWithChildren) { } return () => clearTimeout(timer); }, [autoplay, autoplayDelay, indexMap, totalLen]); - + const nodeRef = useRef(null); return (
- +
) { left: `${-bound?.width!}px` }} className={animation.direction} + ref={nodeRef} > {state.map((v, i) => (
>, - delay: number + delay: number, + nodeRef: React.RefObject ) => { const classes = classNames("bigbear-submenu-children", { "bigbear-menuopen": menuopen @@ -60,13 +61,17 @@ const renderChildren = ( console.error("submenu must in menuItem"); } }); + return ( -
    {childrenComponent}
+
    + {childrenComponent} +
); }; @@ -131,6 +136,7 @@ export const SubMenu: FC = (props) => { setMenuopen(true); } }, [isopen]); + const nodeRef = useRef(null); return (
  • = (props) => { {title ? title : null} {icon && }
  • - {renderChildren(children, menuopen, index, context.mode, setMenuopen, delay!)} + {renderChildren(children, menuopen, index, context.mode, setMenuopen, delay!, nodeRef)} ); }; diff --git a/src/components/Modal/modal.tsx b/src/components/Modal/modal.tsx index ed2152f..174c7a4 100644 --- a/src/components/Modal/modal.tsx +++ b/src/components/Modal/modal.tsx @@ -84,7 +84,12 @@ function Modal(props: PropsWithChildren) { const ref = useRef(null); const render = useMemo(() => { return createPortal( - +
    ) { const [state, setState] = useState(defaultValue!); const [open, setOpen] = useState(false); const ref = useRef(null); + const nodeRef = useRef(null); useClickOutside(ref, () => setOpen(false)); useEffect(() => { if (callback) callback(state); @@ -68,8 +69,8 @@ function Select(props: PropsWithChildren) {
    {icon ?
    {icon}
    : null}
    - -
    + +
    {data.map((item, index) => { let renderRes = renderTemplate ? ( renderTemplate(item, index, setState, setOpen) diff --git a/src/components/Transition/transition.stories.mdx b/src/components/Transition/transition.stories.mdx index 4a6c9a6..1b66ee7 100644 --- a/src/components/Transition/transition.stories.mdx +++ b/src/components/Transition/transition.stories.mdx @@ -9,17 +9,31 @@ import Transition from './transition'; ```jsx - {...your code} ``` +## 注意,严格模式警告需要传递nodeRef消除 + +```jsx +const MyComponent = () => { + const nodeRef = React.useRef(null) + return ( + +
    Fade
    +
    + ) +} +``` + + ## 属性详情 -unmountOnExit boolean 表示是否退出时卸载组件。 +unmountOnExit boolean 退出时卸载组件 \ No newline at end of file diff --git a/src/components/Transition/transition.tsx b/src/components/Transition/transition.tsx index 84a96b3..0aee986 100644 --- a/src/components/Transition/transition.tsx +++ b/src/components/Transition/transition.tsx @@ -1,6 +1,5 @@ import React, { FC } from "react"; import { CSSTransition } from "react-transition-group"; -import { CSSTransitionClassNames } from "react-transition-group/CSSTransition"; import { TransitionProps } from "react-transition-group/Transition"; export type AnimationName = @@ -12,7 +11,7 @@ export type AnimationName = type InnerProps = TransitionProps & { /** 需要自行添加css,动画名-enter,-enter-active,exit,-exit-active,原理就是改变类名产生动画效果 */ - classNames?: string | CSSTransitionClassNames; + classNames?: string; }; export type TransitionProp = InnerProps & {