I get an error message on my localhost port on the browser, I haven't deployed yet my code:
TypeError: Object(...) is not a function
NewEvent src/events/pages/NewEvent.js:51
Here my react versions in 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"
},
I have import in my pages NewEvent.js :
import React, {useCallBack , useReducer} from 'react';
In the same page I have nested in a function another function:
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,
});
}, []);
The issue shows in the browser is the following line :
const inputHandler = useCallBack((id,value,isValid) => {
useCallBack is supposed to stop the code to loop when there is several function.. I checked online in other post it seems to be link with the version of react, but I am not sure and quite confused.
Here the messages in the console:
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
The message showing on the browser :
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
Anyone has an idea of the issue, please?
-- Sorry my post is very long -- :D