Giter Site home page Giter Site logo

would using shouldComponentUpdate instead of componentWillReceiveProps give performance increases? about react-native-animatable HOT 4 CLOSED

oblador avatar oblador commented on August 11, 2024
would using shouldComponentUpdate instead of componentWillReceiveProps give performance increases?

from react-native-animatable.

Comments (4)

oblador avatar oblador commented on August 11, 2024

You're onto something, but using shouldComponentUpdate here is a breaking change and might lead to unintended bugs as child components might not be pure. We could perhaps introduce it in a major version bump. For the moment it's better to make your child components implement shouldComponentUpdate/extend PureComponent if they have heavy render() functions.

from react-native-animatable.

oblador avatar oblador commented on August 11, 2024

I've decided that I don't want to implement this.

  1. It doesn't solve the propagation of updates/render when triggering an animation.
  2. It's much better if this is up to the end user to decide where pure components makes sense.

from react-native-animatable.

faceyspacey avatar faceyspacey commented on August 11, 2024

the way i ended up making my animated component is simply with a forceUpdate prop, which is compared in shouldComponentUpdate to determine whether to render children. So basically I came to the same conclusions as you, but built first-class support for it into the solution. It does have its downsides (the main one being that it's basically a requirement to always provide a hash as the forceUpdate prop), but I've found rendering on web using RNW just to be completely horrible compared to regular RN, so such things make a huge difference when animating and renderings happen at the same time.

from react-native-animatable.

faceyspacey avatar faceyspacey commented on August 11, 2024

for reference:

shouldComponentUpdate(nextProps, nextState) {
    let shouldUpdate = true; //non-animation-related props changed (therefore we dont need to worry about rendering during animation, and should definitely update)

    this.properties.forEach((prop) => {
      if(this.props[prop] !== nextProps[prop]) {
        shouldUpdate = false; //new props are related to animation, and therefore renderings should ideally be blocked
        this.animate(this[prop], nextProps[prop], nextProps);
      }
    });

    if(shouldUpdate === false) {
      //allow calling code to specify that they should always update during animations (i.e. because nested children change at the same time)
      if(this.props.updateOnAnimate) {
        return true;
      }

      //allow calling code to provide a hash for efficient situation-specific comparison
      if(nextProps.forceUpdate !== this.props.forceUpdate) {
        return true;
      }

      return false;
    }

    return true;
  }

from react-native-animatable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.