reactjs - 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};
解决方案
你应该定义你的变量,使用 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};
推荐阅读
- r - 如何在一行中转换不同的级别
- javascript - 更改 a 的值
- android - 在我的情况下如何使用黄油刀?
- c# - C# 如何使用 Directory.GetPath LINQ 限制子文件夹的结果
- javascript - 'util.promisify(setTimeout)' 和 'ms => new Promise(resolve => setTimeout(resolve, ms))' 之间的区别
- python - pygame 不会只加载一张图片
- drivers - 从 MSI 能力结构中读取地址
- php - 使用 varchar 数据确定何时在 php/html/css 中设置 div 类的显示
- php - 有什么方法可以检查用户是否订阅了我的 youtube 频道
- python - 即使捕获到异常,hasattr 也会返回属性错误