Skip to content

Instantly share code, notes, and snippets.

@D-Maher
Last active March 16, 2023 23:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save D-Maher/8d8dc3c1b36e250c1a8b81f93bdadeee to your computer and use it in GitHub Desktop.
Save D-Maher/8d8dc3c1b36e250c1a8b81f93bdadeee to your computer and use it in GitHub Desktop.
React component with local state
import React, { useState } from "react";
function Counter() {
const [count, setCount] = useState(0);
const increment = () => {
setCount(count + 1);
};
const decrement = () => {
setCount(count - 1);
};
return (
<div>
<p>Count: {count}</p>
<button onClick={increment}>Increment</button>
<button onClick={decrement}>Decrement</button>
</div>
);
}
export default Counter;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment