Created
March 9, 2021 15:11
-
-
Save jacques-blom/dad4a23bb74e30f76f8e891cb3f19f19 to your computer and use it in GitHub Desktop.
Data Fetching 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import {Container, Heading, Text} from '@chakra-ui/layout' | |
import {Select} from '@chakra-ui/select' | |
import {atom, useRecoilState} from 'recoil' | |
const userIdState = atom<number | undefined>({ | |
key: 'userId', | |
default: undefined, | |
}) | |
export const Async = () => { | |
const [userId, setUserId] = useRecoilState(userIdState) | |
return ( | |
<Container py={10}> | |
<Heading as="h1" mb={4}> | |
View Profile | |
</Heading> | |
<Heading as="h2" size="md" mb={1}> | |
Choose a user: | |
</Heading> | |
<Select | |
placeholder="Choose a user" | |
mb={4} | |
value={userId} | |
onChange={(event) => { | |
const value = event.target.value | |
setUserId(value ? parseInt(value) : undefined) | |
}} | |
> | |
<option value="1">User 1</option> | |
<option value="2">User 2</option> | |
<option value="3">User 3</option> | |
</Select> | |
{userId !== undefined && ( | |
<div> | |
<Heading as="h2" size="md" mb={1}> | |
User data: | |
</Heading> | |
<Text> | |
<b>Name:</b> Example Value | |
</Text> | |
<Text> | |
<b>Phone:</b> Example Value | |
</Text> | |
</div> | |
)} | |
</Container> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you very much for this help , you are awesome