Created
June 12, 2019 07:19
-
-
Save koss-lebedev/1b321962c4685da5c18245fbdbf735bd to your computer and use it in GitHub Desktop.
This file contains hidden or 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 * as React from "react" | |
import { Stack, addPropertyControls, ControlType } from "framer" | |
import { ContactItem } from "./canvas" | |
type Props = { | |
count: number | |
} | |
export function ContactList({ count = 5 }: Props) { | |
const [users, setUsers] = React.useState([]) | |
React.useEffect(() => { | |
fetch(`https://randomuser.me/api/?results=${count}`).then(response => { | |
response.json().then(json => { | |
setUsers(json.results) | |
}) | |
}) | |
}, [count]) | |
return ( | |
<Stack gap={0} alignment="start"> | |
{users.map(user => ( | |
<ContactItem | |
key={user.name.last} | |
name={`${user.name.first} ${user.name.last}`} | |
email={user.email} | |
avatar={user.picture.medium} | |
/> | |
))} | |
</Stack> | |
) | |
} | |
addPropertyControls(ContactList, { | |
count: { | |
type: ControlType.Number, | |
title: "count", | |
defaultValue: 5, | |
}, | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment