Skip to content

Instantly share code, notes, and snippets.

@koss-lebedev
Created June 12, 2019 07:19
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save koss-lebedev/1b321962c4685da5c18245fbdbf735bd to your computer and use it in GitHub Desktop.
Save koss-lebedev/1b321962c4685da5c18245fbdbf735bd to your computer and use it in GitHub Desktop.
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