Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to solve "useRef is not function error" in react js

I am trying use rc-time-picker,but i am getting following error Please check below error,what i am getting Align.js:88 Uncaught TypeError: react__WEBPACK_IMPORTED_MODULE_0___default.a.useRef is not a function at Align (Align.js:88) at updateForwardRef (react-dom.development.js:13581) at beginWork (react-dom.development.js:14402) at performUnitOfWork (react-dom.development.js:16627) at workLoop (react-dom.development.js:16667) at HTMLUnknownElement.callCallback (react-dom.development.js:107) at Object.invokeGuardedCallbackDev (react-dom.development.js:144) at invokeGuardedCallback (react-dom.development.js:191) at replayUnitOfWork (react-dom.development.js:16042) at renderRoot (react-dom.development.js:16724) at performWorkOnRoot (react-dom.development.js:17352) at performWork (react-dom.development.js:17274) at performSyncWork (react-dom.development.js:17247) at interactiveUpdates$1 (react-dom.development.js:17528) at interactiveUpdates (react-dom.development.js:2248) at dispatchInteractiveEvent (react-dom.development.js:4749)

like image 703
Ashok Sudagani Avatar asked Dec 06 '19 06:12

Ashok Sudagani


People also ask

Can useRef be a function?

The useRef Hook is a function that returns a mutable ref object whose . current property is initialized with the passed argument ( initialValue ).

How do you use useRef in React form?

“useRef” React Hook can be used to create Uncontrolled Elements. These elements can be accessed using the DOM Reference. While creating an Uncontrolled Element, we use the keyword “ref”, which points out to a reference object, storing the DOM reference of the elements rendered in the component.

How is useRef used in functional component?

The useRef is a hook that allows to directly create a reference to the DOM element in the functional component. Syntax: const refContainer = useRef(initialValue); The useRef returns a mutable ref object.


1 Answers

useRef is a React Hook It was introduced only in React 16.8.

Upgrade your React (and React DOM) to anything after 16.8 and try again.

Sources : https://reactjs.org/docs/hooks-intro.html

"Hooks are a new addition in React 16.8. They let you use state and other React features without writing a class." -FROM THE DOCS

like image 197
Dehan Avatar answered Sep 28 '22 16:09

Dehan