React Redux - 未捕获的错误...不是一个函数

时间:2017-05-02 02:18:57

标签: javascript reactjs react-redux

对此有所了解..

我看到一些问题提供了上述问题的解决方案,但这不是减速器,而是简单的功能。

奇怪的是,在调用和检索的另一个文件中,我有几乎完全相同的结构,在这种情况下,是一个令牌,它可以工作。在上面的例子中我几乎遵循相同的模式,但是当我在这种情况下运行程序时,它告诉我我所调用的不是函数。

好的,所以我在这里调用函数,包括该函数文件的import语句。

import { saveSelectData, confirmSelectDataExistance } from '../selectData/localStorageDropDowns'
....
    //selectData download if nothing is local storage.
    const testSelectDataExistance = confirmSelectDataExistance()
    if (testSelectDataExistance) {
....

..这是上面confirmSelectDataExistance引用的代码块:

export const confirmSelectDataExistance = () => {
  const companyStateShortNameJson = localStorage.getItem(COMPANYSTATESHORTNAME)
  const statesJson = localStorage.getItem(STATES)
  const suburbLocationsJson = localStorage.getItem(LOCATIONS)
  if (companyStateShortNameJson || statesJson || suburbLocationsJson) {
    console.log('something exists in localstorage')
    return true
  }
    console.log('nothing in localstorage')
  return null
}

它非常简单,真的可以测试localStorage中是否有任何内容。

现在正如我所说,我在这方面是全新的。我可能没有添加足够的信息。让我知道。正如我所说,我有一个相同的模式来检索一个令牌,它的工作完美。但是,这会引发此错误。

Uncaught TypeError: (0 , _localStorageDropDowns.confirmSelectDataExistance) is not a function
at reducer.js:30
at index.js:11
at Object.requestLoginToken (LoginContainer.jsx:33)
at LoginContainer._this.submit (LoginContainer.jsx:19)
at doSubmit (handleSubmit.js:39)
at handleSubmit (handleSubmit.js:101)
at Form.submit (reduxForm.js:566)
at Object.ReactErrorUtils.invokeGuardedCallback (ReactErrorUtils.js:70)
at executeDispatch (EventPluginUtils.js:85)
at Object.executeDispatchesInOrder (EventPluginUtils.js:108)

鉴于我有相同的模式工作,必须有一些我错过的或一个简单的语法错误。

修改

以下是“localStorageDropDowns”的完整文件

const LOCATIONS = 'suburbLocations'
const STATES = 'states'
const COMPANYSTATESHORTNAME = 'comapanyStateShortName'


export const saveSelectData = (data) => {
  console.log('select Data', data)
  const suburbLocationsJson = JSON.stringify(data.suburbPostcodeDropDownList)
  const statesJson = JSON.stringify(data.stateDropDownList)
  const companyStateShortNameJson = JSON.stringify(data.companyStateShortName)
  localStorage.setItem(LOCATIONS, suburbLocationsJson)
  localStorage.setItem(STATES, statesJson)
  localStorage.setItem(COMPANYSTATESHORTNAME, companyStateShortNameJson)
}

export const confirmSelectDataExistance = () => {
  const companyStateShortNameJson = localStorage.getItem(COMPANYSTATESHORTNAME)
  const statesJson = localStorage.getItem(STATES)
  const suburbLocationsJson = localStorage.getItem(LOCATIONS)
  if (companyStateShortNameJson || statesJson || suburbLocationsJson) {
    console.log('something exists in localstorage')
    return true
  }
    console.log('nothing in localstorage')
  return null
}

只有两个要保存的函数和一个用于检测localStorage是否有数据的函数。

0 个答案:

没有答案