Created
August 23, 2018 14:39
-
-
Save matthew-gerstman/39db0e7769d346bddf35d34f02e72770 to your computer and use it in GitHub Desktop.
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
// wizards.tsx | |
import * as React from "react"; | |
import { connect, Provider } from "react-redux"; | |
import { getStoreForWizardApp } from "./data/wizards/store"; | |
import { Wizard } from "./data/wizards/types"; | |
import { getWizards } from "./data/wizards/selectors"; | |
export function WizardApp() { | |
return ( | |
<Provider store={getStoreForWizardApp()}> | |
<ConnectedWizards /> | |
</Provider> | |
); | |
} | |
function Wizard({ name, spells, parentsAlive }: Wizard) { | |
return ( | |
<> | |
<span>Name: {name}</span> | |
<span>Parents: {parentsAlive ? "Alive" : "Dead"}</span> | |
<span>Learned Spells: {spells.map(spell => `${spell} `)}</span> | |
</> | |
); | |
} | |
type WizardsProps = { wizards: Wizard[] }; | |
function Wizards({ wizards }: WizardsProps) { | |
return ( | |
<> | |
{wizards.map(wizardProps => ( | |
<Wizard {...wizardProps} /> | |
))} | |
</> | |
); | |
} | |
const mapStateToProps = state => ({ | |
wizards: getWizards(state) | |
}); | |
const ConnectedWizards = connect<WizardsProps, {}, {}>(mapStateToProps)( | |
Wizards | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment