Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Simple React useRef example errors

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(, rootElement)

I’m getting en errors:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

What Am I doing wrong?

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading