简体   繁体   English

我正在尝试在React Native中构建测验应用程序,但导航到以前的报价时遇到问题

[英]I am trying to build a quiz app in react native, but I am having problem navigating to Previous quotes

I am trying to build a quiz app in react native, but I am having problem navigating to Previous quotes. 我正在尝试在react native中构建测验应用程序,但导航到以前的报价时遇到问题。 This is my code, the prevQuote function isn't working. 这是我的代码,prevQuote函数不起作用。

prevQuote = () => {
    const { activeQuoteIndex } = this.state;
    let prevQuote = activeQuoteIndex;
    this.setState({
        prevQuote: activeQuoteIndex - 1,
    });
};

nextQuote = () => {
    const { activeQuoteIndex } = this.state;

    if (activeQuoteIndex < quotes.length - 1) {
        this.setState({
            activeQuoteIndex: Math.floor(Math.random() * activeQuoteIndex + 10),
        });
    }

Try calling setState with a callback like so: 尝试使用类似这样的回调调用setState

this.setState((state) => ({
    prevQuote: state.activeQuoteIndex - 1,
});

More info here . 更多信息在这里

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我在创建反应应用程序时遇到问题 - I am having problem in creating react app 我在创建 React 应用程序时遇到问题 - I am having trouble with creating react app 我正在尝试创建 React App 但我得到了这个输出? - I am trying to create React App but I am getting this output? 我正在尝试动态绑定数据以响应本机选择器,数据已成功绑定到选择器,但我收到以下警告 - i am trying to dynamically bind data to react native picker, the data is binding to the picker successfully , but i am having the following warning 开始学习 react,我正在尝试使用 unsplash API 构建一个简单的图像搜索,但是我无法渲染到页面 - Started learning react and I am trying to build a simple image search using unsplash API but I am having trouble rendering to the page 我正在尝试打开 React Native 应用程序,但我遇到了这个问题,解决办法是什么? - I am trying to open the React Native application but I have this problem What is the solution? 我正在尝试构建 apk,但在 react-native 中出现此错误 - i am trying to build apk but i get this error in react-native 我正在使用 ag-grid 构建 React 应用程序,但在尝试如何在单元格中放置链接时遇到问题 - I am building react app with ag-grid and I am having an issue with trying how to put a link in the cell 我正在尝试在选择器中传递多个道具反应原生但有一些问题 - I am trying to pass multiple props in picker react native but have some problem 尝试编译React Native应用程序时,我收到关于React.js不存在的错误 - Trying to compile React Native app and I am getting an error about React.js not existing
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM