Skip to content

Instantly share code, notes, and snippets.

Last active April 4, 2021 17:14
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
useEffect with no dependencies
import React, { useState, useEffect } from "react";
import ReactDOM from "react-dom";
const App = () => {
const [counter, setCounter] = useState(0);
const [username, setUsername] = useState("");
useEffect(() => {
console.log("useEffect executed");
return (
<p>Counter value is: {counter} </p>
<button onClick={() => setCounter(counter + 1)}>Increment</button>
<br />
<br />
Name{" "}
placeholder="Enter your name"
onChange={event => setUsername(}
<br />
ReactDOM.render(<App />, document.getElementById("root"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment