如何仅禁用 react native 上的 setState 消息警告
How to disable only the setState message warning on react native
我想禁用 setState 消息警告
在布局 1 上:
我的构造函数:
constructor(props){
super(props);
//Constructeur
this.lestachesitemsRef=getDatabase().ref('n0rhl66bifuq3rejl6118k8ppo/lestaches'); this.lestachesitems=[];
this.state={
//Debutdustate
lestachesSource: new ListView.DataSource({rowHasChanged: (row1, row2)=>row1 !== row2}),
Prenom: '',
Nom: '',}
}
我的函数:
ajouter= () => {
if( (this.state.Nom !== '') && (this.state.Prenom !== '')) { this.lestachesitemsRef.push({ Nom: this.state.Nom , Prenom: this.state.Prenom , }); this.setState({ Nom : '' }) , this.setState({ Prenom : '' }) }
}
我的componentDidMount
componentDidMount()
{
//DidMount
this.lestachesitemsRef.on('child_added', (dataSnapshot)=>{ this.lestachesitems.push({id: dataSnapshot.key, text: dataSnapshot.val()}); this.setState({lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)}); });
this.lestachesitemsRef.on('child_removed', (dataSnapshot)=>{ this.lestachesitems = this.lestachesitems.filter((x)=>x.id !== dataSnapshot.key); this.setState({ lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)});});
}
我的看法:
<TextInput style={styles.Dtext} placeholder="Nom" onChangeText={(text) => this.setState({Nom: text})} value={this.state.Nom}/>
<TextInput style={styles.Dtext} placeholder="Prenom" onChangeText={(text) => this.setState({Prenom: text})} value={this.state.Prenom}/>
<Button title='Allerlayout2' onPress={() => this.verl2()} onLongPress={() => this.infol2()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
<Button title='ajouter' onPress={() => this.ajouter()} onLongPress={() => this.infoajout()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
<ListView dataSource={this.state.lestachesSource} renderRow={this.renderRowlestaches.bind(this)} enableEmptySections={true} />
Layout2 与Layout1 相同。
谢谢!
警告
警告将以黄色背景显示在屏幕上。这些警报称为 YellowBoxes。单击警报以显示更多信息或将其关闭。
与 RedBox 一样,您可以使用 console.warn() 来触发 YellowBox。
在开发过程中可以使用 console.disableYellowBox = true; 禁用 YellowBoxes。可以通过设置应忽略的前缀数组以编程方式忽略特定警告:console.ignoredYellowBox = ['Warning: ...'];.
在 CI/Xcode 中,也可以通过设置 IS_TESTING 环境变量来禁用 YellowBoxes。
http://facebook.github.io/react-native/docs/debugging.html#yellowbox-redbox
我想禁用 setState 消息警告
在布局 1 上: 我的构造函数:
constructor(props){
super(props);
//Constructeur
this.lestachesitemsRef=getDatabase().ref('n0rhl66bifuq3rejl6118k8ppo/lestaches'); this.lestachesitems=[];
this.state={
//Debutdustate
lestachesSource: new ListView.DataSource({rowHasChanged: (row1, row2)=>row1 !== row2}),
Prenom: '',
Nom: '',}
}
我的函数:
ajouter= () => {
if( (this.state.Nom !== '') && (this.state.Prenom !== '')) { this.lestachesitemsRef.push({ Nom: this.state.Nom , Prenom: this.state.Prenom , }); this.setState({ Nom : '' }) , this.setState({ Prenom : '' }) }
}
我的componentDidMount
componentDidMount()
{
//DidMount
this.lestachesitemsRef.on('child_added', (dataSnapshot)=>{ this.lestachesitems.push({id: dataSnapshot.key, text: dataSnapshot.val()}); this.setState({lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)}); });
this.lestachesitemsRef.on('child_removed', (dataSnapshot)=>{ this.lestachesitems = this.lestachesitems.filter((x)=>x.id !== dataSnapshot.key); this.setState({ lestachesSource: this.state.lestachesSource.cloneWithRows(this.lestachesitems)});});
}
我的看法:
<TextInput style={styles.Dtext} placeholder="Nom" onChangeText={(text) => this.setState({Nom: text})} value={this.state.Nom}/>
<TextInput style={styles.Dtext} placeholder="Prenom" onChangeText={(text) => this.setState({Prenom: text})} value={this.state.Prenom}/>
<Button title='Allerlayout2' onPress={() => this.verl2()} onLongPress={() => this.infol2()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
<Button title='ajouter' onPress={() => this.ajouter()} onLongPress={() => this.infoajout()} buttonStyle={ styles.View } icon={{name: 'squirrel', type: 'octicon', buttonStyle: styles.View }} />
<ListView dataSource={this.state.lestachesSource} renderRow={this.renderRowlestaches.bind(this)} enableEmptySections={true} />
Layout2 与Layout1 相同。 谢谢!
警告 警告将以黄色背景显示在屏幕上。这些警报称为 YellowBoxes。单击警报以显示更多信息或将其关闭。 与 RedBox 一样,您可以使用 console.warn() 来触发 YellowBox。 在开发过程中可以使用 console.disableYellowBox = true; 禁用 YellowBoxes。可以通过设置应忽略的前缀数组以编程方式忽略特定警告:console.ignoredYellowBox = ['Warning: ...'];. 在 CI/Xcode 中,也可以通过设置 IS_TESTING 环境变量来禁用 YellowBoxes。
http://facebook.github.io/react-native/docs/debugging.html#yellowbox-redbox