Skip to content

Instantly share code, notes, and snippets.

@jcarroll2007
Created March 23, 2021 12:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jcarroll2007/75983af129db251e3c801ea745c47b76 to your computer and use it in GitHub Desktop.
Save jcarroll2007/75983af129db251e3c801ea745c47b76 to your computer and use it in GitHub Desktop.
React Architecture Blog Post: Character List Container
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