Skip to content

Instantly share code, notes, and snippets.

@reime005
Created December 27, 2020 22:30
Embed
What would you like to do?
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