Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@cpojer
Last active August 29, 2015 14:27
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 cpojer/efd40a8ab091fe16a2f3 to your computer and use it in GitHub Desktop.
Save cpojer/efd40a8ab091fe16a2f3 to your computer and use it in GitHub Desktop.
function matchRoute<T>(
route: {name: string},
map: {[key: string]: () => T}
): ?T {
return map[route.name] ? map[route.name]() : null;
}
// Usage
matchRoute(this.props.route, {
'ProfileRoute': () => <Profile {...props} />,
'StoryRoute': () => <Story {...props} />,
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment