Skip to content

Instantly share code, notes, and snippets.

@jth0024
Last active May 17, 2022 14:49
Show Gist options
  • Save jth0024/9351c505ffd915538ae5d4efa6d550c3 to your computer and use it in GitHub Desktop.
Save jth0024/9351c505ffd915538ae5d4efa6d550c3 to your computer and use it in GitHub Desktop.
A component using its "Component Hook"
import React from 'react';
import { useCharacterList } from './useCharacterList';
import {
Button,
Wrapper,
List,
ListItem,
ListItemInfo,
NameWrapper,
IsJediWrapper,
HeaderTypography,
Spinner,
} from './styles';
export const CharacterList = () => {
const [data, handlers] = useCharacterList();
const { characters, loading } = data;
const { onRefresh } = handlers;
return (
<Wrapper>
Star Wars Characters
<Button onClick={onRefresh}>Refresh List</Button>
{loading ? <Spinner /> : (
<List>
<ListItem>
<NameWrapper>
<HeaderTypography>
Name
</HeaderTypography>
</NameWrapper>
<ListItemInfo>
<HeaderTypography>
Age
</HeaderTypography>
</ListItemInfo>
<IsJediWrapper>
<HeaderTypography>
isJedi
</HeaderTypography>
</IsJediWrapper>
</ListItem>
{characters.map((c) => (
<ListItem key={c.name}>
<NameWrapper>
{c.name}
</NameWrapper>
<ListItemInfo>
{c.age}
</ListItemInfo>
<IsJediWrapper>
{c.isJedi ? 'True' : 'False'}
</IsJediWrapper>
</ListItem>
))}
</List>
)}
</Wrapper>
);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment