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

2

8

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)

Dustan answered 6/12, 2019 at 6:46 Comment(2)
can you post your code that you tried because for me it's workingRozalin
Actually for me also it is working for new web app(react-version:16.12),after that I tried to add my project,at that time it is gettting issue(react-version: 16.4)Dustan
S
6

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

Sisyphus answered 6/12, 2019 at 7:58 Comment(0)
M
-2

make sure you imported the useRef dependency from React

import React, { useRef } from "react";
Macrobiotics answered 2/10, 2021 at 22:20 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Pluviometer

© 2022 - 2024 — McMap. All rights reserved.