ReactJS:解析错误。未定义导出 "NextQuestion"。

问题描述 投票:0回答:1

我很困惑,为什么我的箭头函数不能导出。我收到了 "解析错误。"Export 'NextQuestion' is not defined" 我不确定为什么。这是我的代码。

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};
reactjs function react-native react-redux helper
1个回答
0
投票

你应该定义你的变量,使用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};
© www.soinside.com 2019 - 2024. All rights reserved.