相关疑难解决方法(0)

在React/React Native中使用构造函数与getInitialState有什么区别?

我看过两者都可以互换使用.

两者的主要用例是什么?有优点/缺点吗?这是一个更好的做法吗?

constructor reactjs react-native

581
推荐指数
4
解决办法
20万
查看次数

如何在ReactJS中使用ref触发动画

这是我的演示: https: //stackblitz.com/edit/react-pwdkse 注意:使用您的浏览器控制台而不是 Stackblitz 的控制台。看来浏览器控制台在信息反馈方面更加完整

我将使用 ReactJSref的引用触发动画,而不是更改元素范围内的 className 。目前什么也没有发生。

我可能会错过什么?

这是我的 React 片段:

成分

import React, { Component } from 'react';
import { render } from 'react-dom'; 
import './style.module.css';

class App extends Component {
  constructor() {
    super();
    this.state = {
      name: 'React'
    };
     this.animateRef = React.createRef();
  //  this.triggerAnimation = this.triggerAnimation.bind(this);
  }

  componentDidMount(){ 
    // empty scope right now
  }

   triggerAnimation=()=>{ 
      console.log("trigger animateRef animation")

      //   this.animateRef.current.style.animationName="animateElement"
      //  this.animateRef.current.style.animation="1.5s 4.3s 3 alternate forwards"
       this.animateRef.current.className.concat(`animation_trigger`)
        console.log("animateRef: ", this.animateRef)
  }



  render() { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs

6
推荐指数
1
解决办法
6097
查看次数

标签 统计

reactjs ×2

constructor ×1

javascript ×1

react-native ×1