Search code examples
javascriptreact-nativecountdown

React Native countDown Timer using a Json response object as a limit date


i'm tring to use countdown timer using a json response as a limit date (Replacing the until={this.state.totalDuration} with until={item.date} ) but i failed i always have NaN NaN NaN . how ever if i change the until value directly for example (until={'2020-12-12'}) i don't get a NaN NaN NaN in the countdown but i get a count down that goes down from 30 min and that's akward

<Content >
     <View style ={{ flex:1}}>
       <FlatList
         data={this.state.data}
         keyExtractor={(item,index) => index.toString()}
         renderItem={({item}) =>
          <View style={{backgroundColor:'#e6e6e6',padding:10,margin:10}}>
            <ListItem icon>
              <Left>
                <Button style={{ backgroundColor: "white" }}>
                  <Icon0 active name="doctor" />
                </Button>
              </Left>
              <Body>
                <Text>Nom du Docteur : Dr. {item.nom}</Text>
              </Body>
            </ListItem>
            <ListItem icon>
              <Left>
                <Button style={{ backgroundColor: "white" }}>
                  <Icon1 active name="calendar" />
                </Button>
              </Left>
              <Body>
                <Text>Date du rendez-vous : {item.date}</Text>
              </Body>
            </ListItem>
            <ListItem icon>
              <Left>
                <Button>
                  <Icon1 active name="calendar"/>
                </Button>
              </Left>
              <Body>
                <CountDown
                  until={item.date}
                  timetoShow={('H', 'M', 'S')}
                  onFinish={() => alert('finished')}
                  onPress={() => alert('hello')}
                  size={10}
                />
            </Body>
          </ListItem>
        </View>
      }
    />
  </View>
</Content>

Edit: * Imports

import CountDown from 'react-native-countdown-component';
import moment from 'moment';

Solution

  • Problem was that in 'react-native-countdown-component' the until takes an integer argument which is the date is Seconds so you have to convert your date into seconds .