Skip to content

Instantly share code, notes, and snippets.

@haldarmahesh
Created October 29, 2018 00:01
Show Gist options
  • Save haldarmahesh/3208f4804e4dcb92e632556b003ef2f2 to your computer and use it in GitHub Desktop.
Save haldarmahesh/3208f4804e4dcb92e632556b003ef2f2 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from 'react';
export default function counterHook() {
const [count, setCount] = useState(0);
useEffect(() => {
document.title = "Count is " + count;
});
return (
<div>
<div>
<button onClick={() => setCount(count + 1)}> + Increment</button>
<button onClick={() => setCount(count - 1)}> - Decrement</button>
</div>
<div>
Current: {count}
</div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment