ReferenceError:从另一个模块导入时未定义变量

时间:2020-08-26 04:38:51

标签: javascript reactjs next.js

index.js

import React from 'react'
import { master, setMaster } from './variableTest'

export default Home () {
  [signedIn, setSignedIn] = React.useState(false)
  [master, setMaster] = React.useState([])

  return (<>...</>)
}

variableTest.js

var master, setMaster

export default master
export { master, setMaster }

现在,signedIn[],但是mastersetMaster仍未定义。

我在;的末尾添加了[signedIn, setSignedIn] = React.useState(false)

index.js

import React from 'react'
import { master, setMaster } from './variableTest'

export default Home () {
  [signedIn, setSignedIn] = React.useState(false);
  [master, setMaster] = React.useState([])

  return (<>...</>)
}

The screenshot of the error

发生错误:master未定义。

在构建master时,我想给setMasterHome()一个新值。

0 个答案:

没有答案