Sumário
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
| const ActiveUsersList = () => { | |
| const [users, setUsers] = useState([]) | |
| useEffect(() => { | |
| const loadUsers = async () => { | |
| const response = await fetch('/some-api') | |
| const data = await response.json() | |
| setUsers(data) | |
| } |
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
| const useUsers = () => { | |
| const [users, setUsers] = useState([]) | |
| useEffect(() => { | |
| const loadUsers = async () => { | |
| const response = await fetch('/some-api') | |
| const data = await response.json() | |
| setUsers(data) | |
| } |
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
| onst UserItem = ({ user }) => { | |
| return ( | |
| <li> | |
| <img src={user.avatarUrl} /> | |
| <p>{user.fullName}</p> | |
| <small>{user.role}</small> | |
| </li> | |
| ) | |
| } |
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
| const getOnlyActive = (users) => { | |
| const weekAgo = new Date() | |
| weekAgo.setDate(weekAgo.getDate() - 7) | |
| return users.filter(user => !user.isBanned && user.lastActivityAt >= weekAgo) | |
| } | |
| const ActiveUsersList = () => { | |
| const { users } = useUsers() |
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
| const useActiveUsers = () => { | |
| const { users } = useUsers() | |
| const activeUsers = useMemo(() => { | |
| return getOnlyActive(users) | |
| }, [users]) | |
| return { activeUsers } | |
| } |
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
| const Header = () => { | |
| const { pathname } = useRouter() | |
| return ( | |
| <header> | |
| <Logo /> | |
| <Actions> | |
| {pathname === '/dashboard' && <Link to="/events/new">Create event</Link>} | |
| {pathname === '/' && <Link to="/dashboard">Go to dashboard</Link>} | |
| </Actions> |
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
| const Header = ({ children }) => ( | |
| <header> | |
| <Logo /> | |
| <Actions> | |
| {children} | |
| </Actions> | |
| </header> | |
| ) | |
| const HomePage = () => ( |
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
| type Video = { | |
| title: string | |
| duration: number | |
| coverUrl: string | |
| } | |
| type Props = { | |
| items: Array<Video> | |
| } |
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
| type Props = { | |
| video: Video | |
| } | |
| const Thumbnail = ({ video }: Props) => { | |
| return <img src={video.coverUrl} /> | |
| } |
OlderNewer