[RN] fix TimerExample

Summary:
Pressing clear would crash if timer was unmounted.

Fixed by not rendering clear button when timer unmounted.
This commit is contained in:
Spencer Ahrens 2015-08-31 10:00:07 -07:00
parent 6f3849ea7b
commit d080c8dc2b

View File

@ -181,8 +181,12 @@ exports.examples = [
render: function() {
if (this.state.showTimer) {
var timer =
<TimerTester ref="interval" dt={25} type="setInterval" />;
var timer = [
<TimerTester ref="interval" dt={25} type="setInterval" />,
<Button onPress={() => this.refs.interval.clear() }>
Clear interval
</Button>
];
var toggleText = 'Unmount timer';
} else {
var timer = null;
@ -191,9 +195,6 @@ exports.examples = [
return (
<View>
{timer}
<Button onPress={() => this.refs.interval.clear() }>
Clear interval
</Button>
<Button onPress={this._toggleTimer}>
{toggleText}
</Button>