Quantcast
Channel: Active questions tagged react-native+typescript - Stack Overflow
Viewing all articles
Browse latest Browse all 6213

How can I fix the React Native setState error?

$
0
0

First of all, I apologize for my bad English.I am using the select component of the UI Kitten. Every item fails when I change it.

This is the mistake;

"Warning cannot update during an existing state react native"

I am sharing sample codes with you.

const data = ["test 1","test 2"];constructor(props) {  super(props);      this.state = {          selectedIndex: new IndexPath(0),     displayValue: null  };    }componentDidMount() {  this._handleSetSelectedIndex = this._handleSetSelectedIndex.bind(this);}_handleSetSelectedIndex(value) {  this.setState({selectedIndex: value});}

in Render function;

<Select  style={{ width: 300 }}  placeholder='Default'  value={data[this.state.selectedIndex.row]}  selectedIndex={this.state.selectedIndex}  onSelect={index => this._handleSetSelectedIndex(index)}>  {data.map((key, value) => {      return (<SelectItem key={value} title={key}/>    );  })}</Select>

Viewing all articles
Browse latest Browse all 6213

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>