Comments (6)
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.
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.
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.
Also running into this same issue and would love to see it fixed
from react-native-countdown-component.
also same problem. + 1
from react-native-countdown-component.
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)
- Maximum update depth exceeded HOT 3
- Peer dependency error
- SOLVED accuracy
- Dead?
- How can I get the value of the elapsed time to save it in localstorge? HOT 1
- onFinish not work on 00 HOT 1
- EventEmitter needs update HOT 1
- Deprecated AppState.removeEventListener on react v0.70 HOT 9
- Error -4049
- Android Timer decrease with in seconds (very fastly) HOT 5
- AppState.removeEventListener() is deprecated which is used in the index.js file
- EventEmitter.removeListener('appStateDidChange', ...): Method has been deprecated. Please instead use `remove()` on the subscription returned by `EventEmitter.addListener`. HOT 2
- Save yourself a headache: HOT 2
- undefined is not a function (AppState.removeEventListener('change', this._handleAppStateChange) HOT 3
- Volunteer as Maintainer
- maintaining this component
- 'removeEventListener' removed in recent versions of react-native. Replaced with '.remove()'
- [iOS] Timer corrupts when app goes in back ground and comes to foreground HOT 2
- Maximum update depth exceeded. HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-countdown-component.