Code Monkey home page Code Monkey logo

Comments (2)

hraschan avatar hraschan commented on July 18, 2024

Can you maybe fix this issue. Guess thats not mutch work. Would help a lot!

from react-native-stopwatch-timer.

DejaVuMan avatar DejaVuMan commented on July 18, 2024

I'm aware that it is likely this project has been shelved or abandoned for the time being, but in case devs ever come back to this, I wanted to help and provide a suggestion for how to overhaul componentWillRecieveProps for the future.

Currently, the way time updating occurs is with the following function:

  componentWillReceiveProps(newProps) {

    if(newProps.start) {
      this.start();
    } else {
      this.stop();
    }
    if(newProps.reset) {
      this.reset(newProps.totalDuration);
    }
  }

As mentioned above by @JuliaCastillo , this could be resolved for now by changing it to UNSAFE_componentWillRecieveProps,
or alternatively by overhauling the function completely and making use of componentDidUpdate instead.

In limited testing I've done on my end with the timer method, I've found that this works identically and doesn't cause issues:

  componentDidUpdate(prevProps) {
    if (this.props.start !== prevProps.start) {
      if(this.props.start) {
          this.start();
      } else {
          this.stop();
      }
    }
    if (this.props.reset !== prevProps.reset) {
      if(this.props.reset) {
          this.reset(this.props.totalDuration);
      }
    }
}

Not a huge React or JS expert so it's possible this code block could be made better

from react-native-stopwatch-timer.

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.