Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Counter with hooks example.
export const Counter: SFC<RouteComponentProps> = () => {
const [count, setCount] = useState(0);
useEffect(() => {
console.log('count', count);
})
return (
<View>
<h3>Counter</h3>
<p>Counter: {count}</p>
<div>
<button onClick={useCallback(() => {
setCount(count + 1)
console.log("count internal", count);
}, [count])}
>
Add
</button>
<button onClick={useCallback(() => setCount(count - 1), [count])}>Subtract</button>
</div>
</View>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment