1

Having such a simple React App:

import React, { useState, useEffect, useRef } from "react";
import ReactDOM from "react-dom";

function App() {
  const [inputValue, setInputValue] = useState("");
  const count = useRef(0);

  useEffect(() => {
    count.current = count.current + 1;
  });

  return (
    <>
      <input
        type="text"
        //value={inputValue}
        //onChange={(e) => setInputValue(e.target.value)}
      />
      <h1>Render Count: {count.current}</h1>
    </>
  );
}

const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);

I'm getting en errors:

(0 , _react.useState) is not a function (0 , _react.useRef) is not a function

What Am I doing wrong?

3
  • Are you using the same version of react and react-dom on your package.json? Commented May 3, 2022 at 10:28
  • @mchowdam Yes, the same both are 16.5.2. Btw I'm running the code on the codesandbox. Commented May 3, 2022 at 10:30
  • Can you update your question with the sandbox link? Commented May 3, 2022 at 10:31

1 Answer 1

1

React hooks are introduced in 16.8 version. So you can't use useState, useEffect and any hooks in <16.8 version on react.

Documentation

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.