0

I am unable to run this React code snippet using repl.it.

Can you please guide me where I am going wrong.

Nosail
  • 465
  • 2
  • 7
  • 19
  • Even though your issue is occurring on an external site it is still a good idea to include the code and some specific about your environment in you question. – Paul Wheeler Mar 04 '22 at 22:40

1 Answers1

1

Any JavaScript files that contain React templates need to use the .jsx file extension, and then need to import React.

App.jsx

import React from 'react';
import { 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>
    </>
  );
}

export default App;
Paul Wheeler
  • 18,988
  • 3
  • 28
  • 41