Skip to content

Instantly share code, notes, and snippets.

@solidfox
Created March 17, 2018 12:54
Show Gist options
  • Save solidfox/a34548d458e691f64c685a4d6e956592 to your computer and use it in GitHub Desktop.
Save solidfox/a34548d458e691f64c685a4d6e956592 to your computer and use it in GitHub Desktop.
Component with closure of state and dispatch will make React replace everyting inside AppBody on every re-render.
function AppComponent({state, dispatch}) {
// Component with closure of state and dispatch will make React replace everyting
// inside AppBody on every re-render.
function AppBody() {
switch (state.get('page')) {
case "dish-details":
return <DishDetails key='dishDetails'
dish={core.getBestInformationOnSelectedDish(state)}
nGuests={state.get("nGuests")}
dispatch={dispatch}/>
case "dinner-overview":
return <DinnerOverview nGuests={state.get('nGuests')}
menu={core.getMenuDishes(state)}
dispatch={dispatch}/>;
case "print-dinner":
return <PrintDinner nGuests={state.get('nGuests')}
menu={core.getMenuDishes(state)}
dispatch={dispatch}/>;
default:
return <WelcomeView dispatch={dispatch}/>;
}
}
return [
<header key="header">
<h1>Dinner Planner</h1>
</header>,
<AppBody key="body"/>,
<footer key="footer">Lab Group 5 - Daniel Schlaug & Siddhant Gupta</footer>
];
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment