【发布时间】:2020-10-09 05:50:22
【问题描述】:
我对为什么我的箭头函数没有导出感到困惑。我收到了错误“解析错误:未定义导出‘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};
【问题讨论】:
-
我怀疑您在这些方法中使用了
this.setState和this.state,因此如果您将这些方法包含在class组件中,它们将按原样工作。但如果它们在类组件之外使用,则实现可能无法正常工作。
标签: reactjs function react-native react-redux helper