** Updated to implement TimerMixin
You need to call this.setState to update the state variable and, as pointed out by @ eyal83, use TimerMixin for setTimeout and setInterval:
var TimerMixin = require('react-timer-mixin'); componentDidMount: function() { this.setInterval( () => { let d = new Date(); let result = d.getHours() + d.getMinutes() / MINUTES_IN_HOUR; this.setState({ timeLineTop: result }) }, 500); }
I also installed a base application that reloads the state variable using setInterval here , code below. https://rnplay.org/apps/9gD-Nw
'use strict'; var React = require('react-native'); var { AppRegistry, StyleSheet, Text, View, } = React; var TimerMixin = require('react-timer-mixin'); var SampleApp = React.createClass({ mixins: [TimerMixin], getInitialState: function() { return { timeLineTop: 75 } }, componentDidMount: function() { this.setInterval( () => { this.setState({ timeLineTop: this.state.timeLineTop+1 }) }, 500); }, render: function() { return ( <View style={styles.container}> <View style={[ { marginTop: this.state.timeLineTop }, ]}><Text>TOP - {this.state.timeLineTop}</Text></View> </View> ); } }); var styles = StyleSheet.create({ container: { flex: 1, marginTop:60, }, }); AppRegistry.registerComponent('SampleApp', () => SampleApp);
source share