Giter Site home page Giter Site logo

Comments (6)

gerardcsaperas avatar gerardcsaperas commented on June 11, 2024 3

Hi guys,

I was having the same problem and I figured it out. Actually, it's written in the documentation:
Props -> id: string: Counter id, to determine whether to reset the counter or not.

You just have to update your component's id every time your until's prop value changes, as such:

import React, { useEffect, useState } from "react"
import { useSelector, useDispatch } from "react-redux"
import CountDown from "react-native-countdown-component"
import { setRest } from "../data/restSlice"

const Timer = () => {
  const dispatch = useDispatch()
  /** rest time from store */
  const restTime = useSelector((state) => (state as any).rest.value)
  /** countdown component id */
  const [countDownId, setCountDownId] = useState(undefined)

  /**
   * Update countdown component id every time
   * rest time changes.
   *
   * Needed to refresh countdown component.
   */
  useEffect(() => {
    // Generate new id based on unix timestamp (string)
    const id = new Date().getTime().toString()
    // Set id to state
    setCountDownId(id)
  }, [restTime])

  return (
    <CountDown
      id={countDownId}
      until={restTime}
      onFinish={() => dispatch(setRest(0))}
      onPress={() => dispatch(setRest(0))}
      size={30}
      timeToShow={["M", "S"]}
    />
  )
}

Hope it helps!

from react-native-countdown-component.

gredy-devstack avatar gredy-devstack commented on June 11, 2024 1

Maybe you can use props "id".
When you update "until" props value on state you also need to update "id" props value as well.
just use random string generator for "id" and it's working fine for me.

from react-native-countdown-component.

lazynewt avatar lazynewt commented on June 11, 2024

Can someone please update/ commit this change#
componentDidUpdate(prevProps, prevState) { if (this.props.until !== prevProps.until || this.props.id !== prevProps.id) { this.setState({ lastUntil: 0, until: Math.max(this.props.until, 0) }); } }

Or even advise me on how i can which would be even better ?
Thanks.

from react-native-countdown-component.

chrisozgo99 avatar chrisozgo99 commented on June 11, 2024

Also running into this same issue and would love to see it fixed

from react-native-countdown-component.

dieptang avatar dieptang commented on June 11, 2024

also same problem. + 1

from react-native-countdown-component.

pwliuab avatar pwliuab commented on June 11, 2024

you can search pull request, change the original index file to that version,
I have made a pull request to solve this problem.

from react-native-countdown-component.

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.