Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 22:30
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 reime005/86ff3a905b1eef5a359259d4e321c511 to your computer and use it in GitHub Desktop.
Save reime005/86ff3a905b1eef5a359259d4e321c511 to your computer and use it in GitHub Desktop.
import React, { useState, useEffect } from 'react';
import { View, Text, Button } from 'react-native';
export const Example = () => {
const [foo, setFoo] = useState(30);
useEffect(() => {
if (foo >= 42) {
setFoo(42);
}
}, [foo])
return (
<view>
<text>Foo is {foo}.</text>
<button onpress={() => setFoo(foo + 1)} title='Increase Foo!' />
</view>
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment