猿问

更好的ES6方式在React中更新状态

更好的ES6方式在React中更新状态


慕后森
浏览 676回答 1
1回答

Cats萌萌

解决方法可以参照这个代码试一试。const { quotes } = require('./quotes.json')classQuoteScreen extends Component {state = {QuoteIndex: 0}handleUpdateState = () => {this.setState(({ QuoteIndex }) => ({QuoteIndex: (QuoteIndex + 1) % (quotes.length - 1)}));}render() {return (<Image ...><View ...>...<ButtonNextQuoteonPress={this.handleUpdateState}/></View></Image>)}}
随时随地看视频慕课网APP
我要回答