Skip to content

Instantly share code, notes, and snippets.

@jacques-blom
Created March 9, 2021 15:11
Show Gist options
  • Save jacques-blom/dad4a23bb74e30f76f8e891cb3f19f19 to your computer and use it in GitHub Desktop.
Save jacques-blom/dad4a23bb74e30f76f8e891cb3f19f19 to your computer and use it in GitHub Desktop.
Data Fetching 1
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>
)
}
@mahdisoultana
Copy link

thank you very much for this help , you are awesome

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment