Last active
May 17, 2022 14:49
-
-
Save jth0024/9351c505ffd915538ae5d4efa6d550c3 to your computer and use it in GitHub Desktop.
A component using its "Component Hook"
This file contains 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 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