-
Notifications
You must be signed in to change notification settings - Fork 230
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Error when timer finished #32
Comments
Add componentwill Unmount method in your js file . After state , |
I'm having a similar problem. This solution didn't work for me. Do you/does anyone else have another suggestion? |
I found a solution that worked for me. While the timer clears the interval and removes the event listener in the componentWillUnmount lifecycle method, it didn't have anything to handle async requests on unmounted components. I edited the index.js file in the react-native-countdown-component folder. I followed a guide from here when editing it. Essentially add a class field to hold the lifecycle state of the component. Ex: `class CountDown extends React.Component {
Then anywhere where setState is called, I added I'll paste the entire solution below--it should be a simple copy/paste fix in the index.js file. `import React from 'react'; import { StyleSheet, View, Text, TouchableOpacity, AppState } from 'react-native'; const DEFAULT_DIGIT_STYLE = { backgroundColor: '#FAB913' }; class CountDown extends React.Component {
} CountDown.defaultProps = { const styles = StyleSheet.create({ module.exports = CountDown; |
I also have this issue, and the above solution looked promising but ended up breaking the component. Timer doesn't change from 0 0 0 now |
Are you saying it doesn't change from 0 0 0 when finishing? I restart the timer by feeding in a new time for the "until" prop using the "onFinish" prop. `nextChoices = () => {
|
The timer interval is already being cleared in the componentWillUnmount lifecycle method in the index.js file located in the the react-native-countdown-component node_module folder. |
After I upgrade to latest version the problem not show anymore. (I used 2.2.0 before) |
I was able to mitigate this error with a timeout: Method
Component
|
This worked for me. Thanks a lot pal! |
I was able to mitigate this error in another way. I just set display:none in the countdown element's style when the countdown finishes. So it doesn't unmount at all. |
Try this componentWillUnmount() { |
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your application. To fix, cancel all subscriptions and asynchronous tasks in the componentWillUnmount method.
Above Error or warning show when the timer is finished after time.
<CountDown
until = {5}
size={14}
onFinish={() => { (this.state.otp_resend) ? console.log("Sorry No timer") : this.showresendbutton() }}
digitStyle={{backgroundColor: 'transparent',textAlign: 'left',color: '#cccccc', margin:0,height:10}}
digitTxtStyle={{color: '#000000',textAlign: 'left', margin:0}}
timeToShow={['M', 'S']}
timeLabels={{m: '', s: ''}}
style={{ textAlign: 'left', margin:0, }}
showSeparator
/>
showresendbutton= async () => {
this.setState({ otp_resend: true })
}
The text was updated successfully, but these errors were encountered: