我现在正在学习React Native,最近我收到了下面的日志消息。
警告:不推荐使用componentWillMount,它将被删除 下一个主要版本。请改用componentDidMount。暂时的 解决方法,您可以重命名为UNSAFE_componentWillMount。
我正在做本教程" React Native Tutorial:使用JavaScript构建Android应用程序" https://www.raywenderlich.com/178012/react-native-tutorial-building-android-apps-javascript
我该怎么做才能删除邮件?
我安装了react-native-cli并做了react-native init projectName。 我改变了package.json。 我改变了#34;反应":" ^ 16.3.0-alpha.1"到" ^ 16.2.0"然后我做了npm install。
我的package.json
{" name":" PropertyFinder"," version":" 0.0.1"," private" :真的, "脚本":{ "开始":"节点node_modules / react-native / local-cli / cli.js start", "测试":"开玩笑" },"依赖":{ "反应":" ^ 16.2.0", " react-native":" 0.54.0", " react-navigation":" ^ 1.3.0" }," devDependencies":{ " babel-jest":" 22.4.1", " babel-preset-react-native":" 4.0.0", "开玩笑":" 22.4.2", " react-test-renderer":" ^ 16.2.0" }," jest":{ "预设":"反应原生" }}
但仍然显示出警告。
SearchPage.js
'use strict';
import React, { Component } from 'react';
import {
StyleSheet,
Text,
TextInput,
View,
Button,
ActivityIndicator,
Image
} from 'react-native';
// import { StackNavigator } from 'react-navigation';
export default class SearchPage extends Component<{}> {
static navigationOptions = {
title: 'Property Finder',
};
constructor(props) {
super(props);
this.state = {
searchString: 'london'
};
}
_onSearchTextChanged = (event) => {
console.log('_onSearchTextChanged');
this.setState({
searchString: event.nativeEvent.text
});
console.log('Current: ' + this.state.searchString + ', Next: ' + event.nativeEvent.text);
}
render() {
console.log('SearchPage render');
return (
<View style={styles.container}>
<Text style={styles.description}>
Search for houses to buy!
</Text>
<Text style={styles.description}>
Search by place-name or postcode.
</Text>
<View style={styles.flowRight}>
<TextInput
underlineColorAndroid={'transparent'}
style={styles.searchInput}
value={this.state.searchString}
onChange={this._onSearchTextChanged}
placeholder='Search via name or postcode' />
<Button
onPress={() => {}}
color='#48bbec'
title='Go'
/>
</View>
<Image source={require('./Resources/house.png')} style={styles.image} />
</View>
);
}
}
const styles = StyleSheet.create({
description: {
fontSize: 18,
textAlign: 'center',
color: '#656565',
marginBottom: 20,
},
container: {
padding: 30,
marginTop: 65,
alignItems: 'center',
},
welcome: {
fontSize: 20,
textAlign: 'center',
margin: 10,
},
instructions: {
textAlign: 'center',
color: '#333333',
marginBottom: 5,
},
flowRight: {
flexDirection: 'row',
alignItems: 'center',
alignSelf: 'stretch',
},
searchInput: {
height: 36,
padding: 4,
marginRight: 5,
flexGrow: 1,
fontSize: 18,
borderWidth: 1,
borderColor: '#48bbec',
borderRadius: 8,
color: '#48bbec',
},
image: {
width: 217,
height: 138,
},
});
App.js
'use strict';
/**
* Sample React Native App
* https://github.com/facebook/react-native
* @flow
*/
import React, { Component } from 'react';
import {
Platform,
StyleSheet,
Text,
View
} from 'react-native';
import { StackNavigator } from 'react-navigation';
import SearchPage from './SearchPage';
// type Props = {};
const App = StackNavigator({
Home: {
screen: SearchPage,
},
});
export default App;
我的英语不好,抱歉。