Skip to content

Instantly share code, notes, and snippets.

@matthew-gerstman
Created August 23, 2018 14:39
Show Gist options
  • Save matthew-gerstman/39db0e7769d346bddf35d34f02e72770 to your computer and use it in GitHub Desktop.
Save matthew-gerstman/39db0e7769d346bddf35d34f02e72770 to your computer and use it in GitHub Desktop.
// 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