首页 > 解决方案 > ReactJS:解析错误:未定义导出“NextQuestion”

问题描述

我对为什么我的箭头函数没有导出感到困惑。我收到错误“解析错误:未定义导出 'NextQuestion'”,我不知道为什么。这是我的代码:

import React, { Component } from "react"

NextQuestion = () => {
    var neww = true
    this.setState((state) => {
        return {continue: neww}
        }
    )
}

LostALife = () => {
    var newLives = this.state.lives - 1
    this.setState((state) => {
        return {lives: newLives}
        }
    )
}

export {NextQuestion, LostALife};

标签: reactjsfunctionreact-nativereact-reduxhelper

解决方案


你应该定义你的变量,使用 const NextQuestion,你可以在下面看到更新的代码

import React, { Component } from "react"

const NextQuestion = () => {
    var neww = true
    this.setState((state) => {
        return {continue: neww}
        }
    )
}

const LostALife = () => {
    var newLives = this.state.lives - 1
    this.setState((state) => {
        return {lives: newLives}
        }
    )
}

export {NextQuestion, LostALife};

推荐阅读