【问题标题】:How to disable only the setState message warning on react native如何在本机反应中仅禁用 setState 消息警告
【发布时间】:2017-09-22 08:00:53
【问题描述】:

我想禁用 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 : '' })   } 
}

我的组件DidMount

 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 一样。 谢谢!

【问题讨论】:

标签: react-native components warnings setstate


【解决方案1】:

警告 警告将以黄色背景显示在屏幕上。这些警报称为 YellowBoxes。单击警报以显示更多信息或将其关闭。 与 RedBox 一样,您可以使用 console.warn() 来触发 YellowBox。 YellowBoxes 可以在开发过程中使用 console.disableYellowBox = true; 禁用。可以通过设置应忽略的前缀数组以编程方式忽略特定警告:console.ignoredYellowBox = ['Warning: ...'];. 在 CI/Xcode 中,也可以通过设置 IS_TESTING 环境变量来禁用 YellowBoxes。

http://facebook.github.io/react-native/docs/debugging.html#yellowbox-redbox

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-12-15
    • 1970-01-01
    • 1970-01-01
    • 2019-03-26
    • 2012-10-07
    • 2017-01-16
    • 1970-01-01
    相关资源
    最近更新 更多