Skip to content

Instantly share code, notes, and snippets.

@AndreiCalazans
Created November 13, 2018 20:10
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 AndreiCalazans/929e4d879719f707ea4f5208f5fd86f9 to your computer and use it in GitHub Desktop.
Save AndreiCalazans/929e4d879719f707ea4f5208f5fd86f9 to your computer and use it in GitHub Desktop.
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