Created
March 23, 2021 12:52
-
-
Save jcarroll2007/75983af129db251e3c801ea745c47b76 to your computer and use it in GitHub Desktop.
React Architecture Blog Post: Character List Container
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 { useSelector, useDispatch } from 'react-redux'; | |
import { CharacterList } from '../../components/CharacterList' | |
import { ActionList } from '../../components/ActionList'; | |
import { characterListLoadingSelector, characterListSelector } from '../../redux/selectors'; | |
import { actions } from '../../redux/actions'; | |
interface CharacterListContainerProps { | |
createCharacterPath: string | |
} | |
export const CharacterListContainer: React.FunctionComponent<CharacterListContainerProps> = ({ | |
createCharacterPath | |
}) => { | |
const characters = useSelector(characterListSelector); | |
const loading = useSelector(characterListLoadingSelector); | |
const dispatch = useDispatch(); | |
if (!characters) dispatch(actions.fetchCharacters()); | |
if (loading) return <div>loading</div>; | |
return ( | |
<ActionList actions={[{ to: createCharacterPath, label: 'Create a New Character' }]}> | |
{characters ? | |
<CharacterList | |
characters={characters} | |
/> : | |
null | |
} | |
</ActionList> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment