Skip to content

Instantly share code, notes, and snippets.

@ryanflorence
Created September 16, 2016 23:55
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ryanflorence/d7ecaf57d8518b0b969502928567c98a to your computer and use it in GitHub Desktop.
Save ryanflorence/d7ecaf57d8518b0b969502928567c98a to your computer and use it in GitHub Desktop.
const ToggleDisplayMatch = ({ component: Component, ...rest }) => (
<Match {...rest}>
{({ matched, ...props }) => (
<div style={{ display: matched ? 'block' : 'none' }}>
<Component {...props}/>
</div>
)}
</Match>
)
// then use it like this:
<ToggleDisplayMatch pattern="/whatever" component={WhateverPage}/>
<ToggleDisplayMatch pattern="/stuff" component={Stuff}/>
@steida
Copy link

steida commented Sep 17, 2016

Display block / none is an unnecessary abstraction. Just don't render.

@asynxc
Copy link

asynxc commented Sep 17, 2016

is simple and powerful.
I would call it MatchRoute for specificity.
Thnks.

@jgaskins
Copy link

@steida If swapping components results in massive diffs, that pauses the app for a long time with no feedback after clicking a link. Swapping block / none would almost remove that delay.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment