我在浏览器的本地主机端口上收到一条错误消息,我还没有部署我的代码:
TypeError: Object(...) 不是函数
NewEvent src/events/pages/NewEvent.js:51
这是我在 package.json 中的反应版本:
"dependencies": {
"react": "^16.13.1",
"react-dom": "^16.13.1",
"react-router-dom": "5.2.0",
"react-scripts": "^3.2.0",
"react-transition-group": "^4.4.1"
},
我在我的页面中导入了 NewEvent.js :
import React, {useCallBack , useReducer} from 'react';
在同一页面中,我在一个函数中嵌套了另一个函数:
const [formState, dispatch] = useReducer(formReducer, {
inputs: {
title: {
value: '',
isValid: false
},
description: {
value: '',
isValid: false
}
},
isValid: false
});// this is the initial state that needs to be update in the reducer
const inputHandler = useCallBack((id,value,isValid) => {
dispatch({
type: 'INPUT_CHANGE',
value: value,
isValid: isValid,
inputId: id,
});
}, []);
浏览器中显示的问题是以下行:
const inputHandler = useCallBack((id,value,isValid) => {
当有多个函数时,useCallBack 应该停止代码循环。我在其他帖子中在线查看它似乎与反应版本有关,但我不确定并且很困惑。
这里是控制台中的消息:
log.js:24 [HMR] Waiting for update signal from WDS...
NewEvent.js:51 Uncaught TypeError: Object(...) is not a function
at NewEvent (NewEvent.js:51)
at renderWithHooks (react-dom.development.js:14803)
at mountIndeterminateComponent (react-dom.development.js:17482)
at beginWork (react-dom.development.js:18596)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at beginWork$1 (react-dom.development.js:23203)
at performUnitOfWork (react-dom.development.js:22154)
at workLoopSync (react-dom.development.js:22130)
at performSyncWorkOnRoot (react-dom.development.js:21756)
at scheduleUpdateOnFiber (react-dom.development.js:21188)
at updateContainer (react-dom.development.js:24373)
at react-dom.development.js:24758
at unbatchedUpdates (react-dom.development.js:21903)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:24757)
at Object.render (react-dom.development.js:24840)
at Module../src/index.js (index.js:7)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
at Object.1 (Users.js:19)
at __webpack_require__ (bootstrap:784)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
index.js:1 The above error occurred in the <NewEvent> component:
in NewEvent (at App.js:23)
in Route (at App.js:22)
in Switch (at App.js:15)
in main (at App.js:14)
in Router (created by BrowserRouter)
in BrowserRouter (at App.js:11)
in App (at src/index.js:7)
Consider adding an error boundary to your tree to customize error handling behavior.
react-dom.development.js:22665 Uncaught TypeError: Object(...) is not a function
at NewEvent (NewEvent.js:51)
at renderWithHooks (react-dom.development.js:14803)
at mountIndeterminateComponent (react-dom.development.js:17482)
at beginWork (react-dom.development.js:18596)
at HTMLUnknownElement.callCallback (react-dom.development.js:188)
at Object.invokeGuardedCallbackDev (react-dom.development.js:237)
at invokeGuardedCallback (react-dom.development.js:292)
at beginWork$1 (react-dom.development.js:23203)
at performUnitOfWork (react-dom.development.js:22154)
at workLoopSync (react-dom.development.js:22130)
at performSyncWorkOnRoot (react-dom.development.js:21756)
at scheduleUpdateOnFiber (react-dom.development.js:21188)
at updateContainer (react-dom.development.js:24373)
at react-dom.development.js:24758
at unbatchedUpdates (react-dom.development.js:21903)
at legacyRenderSubtreeIntoContainer (react-dom.development.js:24757)
at Object.render (react-dom.development.js:24840)
at Module../src/index.js (index.js:7)
at __webpack_require__ (bootstrap:784)
at fn (bootstrap:150)
at Object.1 (Users.js:19)
at __webpack_require__ (bootstrap:784)
at checkDeferredModules (bootstrap:45)
at Array.webpackJsonpCallback [as push] (bootstrap:32)
at main.chunk.js:1
浏览器上显示的消息:
NewEvent
src/events/pages/NewEvent.js:51
48 | isValid: false
49 | });// this is the initial state that needs to be update in the reducer
50 |
> 51 | const inputHandler = useCallBack((id,value,isValid) => {
| ^ 52 | //this function will received the id of the input that changed, value and answer whether it's valid or not
53 | dispatch({
54 | type: 'INPUT_CHANGE',
View compiled
16 stack frames were collapsed.
Module../src/index.js
请问有人知道这个问题吗?
-- 抱歉我的帖子很长 -- :D