zoukankan      html  css  js  c++  java
  • react 利用高阶组件给页面加上动画

    利用高阶组件给页面加上动画

    并不想让所有的路由都有动画效果,只是想对指定的页面有路由切换效果,可以利用高阶组件来完成。

    # 定义高阶组件

    import React, { Component } from 'react'

    import { CSSTransition } from 'react-transition-group'

    import '../assets/animate.css'

     

    const withAnimation = Cmp => {

      return class extends Component {

        render() {

          return (

            <CSSTransition

              in={this.props.match !== null}

              timeout={600}

              classNames={{

                enter: 'animated',

                enterActive: 'fadeInDown',

                exit: 'animated',

                exitActive: 'fadeOutDown'

              }}

              unmountOnExit

            >

              <Cmp {...this.props} />

            </CSSTransition>

          )

        }

      }

    }

     

    export default withAnimation

     

    # 使用

    const Page = withAnimation(

      class Page extends Component {

     

        render() {

          return <div>高阶组件完成路由切换动画效果</div>

        }

      }

    )

     

     

    <Route path="/home" children={props => <Page {...props} />} />

    App.jsx文件

    高阶组件定义

    需要页面组件中使用高阶组件包裹

    右侧打赏一下 代码改变世界一块二块也是爱
  • 相关阅读:
    2003系统IIS上传文件不能超过200K的解决方案
    ASP从编辑框中获取图片路径
    ASP 编码转换大全 UTF8、GB2312、二进制、十进制代码、十六进制
    解决IE6、IE7、IE8样式不兼容问题
    py2exe setup.py
    Python to 2bit
    python访问ACCESS
    Pamie Web自动化
    Perl 笔记
    常用工具全盗版 汗颜了
  • 原文地址:https://www.cnblogs.com/ht955/p/14922871.html
Copyright © 2011-2022 走看看