=> : 箭头函数,发布与ES6
x => x*x 相当于 f(x) {return x*x;}
promise.then() ,前一个then的返回,作为当前then的第一个参数,递进式调用
fetch('https://facebook.github.io/react-native/movies.json')
.then((response) => response.json())
.then((responseJson) => {
return responseJson.movies;
})
.catch((error) => {
console.error(error);
});
alert要写在动作函数里,写在布局里面,会报错
//错误写法
render() {
return (
Alert.alert('hello'); //报错
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
</View>
);
//正确写法
OnAlive = () => {
Alert.alert(JSON.stringify(Platform));
}
render() {
return (
<View style={styles.container}>
<Text style={styles.welcome}>
Welcome to React Native!
</Text>
<Button
onPress={this.OnAlive}
title="alive"
accessibilityLabel="See an informative alert"
/>
</View>
);