Skip to content

Instantly share code, notes, and snippets.

@ryardley
Created August 11, 2016 20:18
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 ryardley/4552819c48fbf12ab03a4ffe0826b4f0 to your computer and use it in GitHub Desktop.
Save ryardley/4552819c48fbf12ab03a4ffe0826b4f0 to your computer and use it in GitHub Desktop.
const Switch = (props) => <span>{props.children}</span>;
const Case = (props) => props.expr && props.children;
const TestInstantiated = (props) => {
console.log(`${props.id}: I was rendered`);
return <div>{props.id}</div>;
}
function TestSwitch() {
const val = 3;
return (
<Switch>
<Case expr={val === 1}>
<TestInstantiated id="1">One</TestInstantiated>
</Case>
<Case expr={val === 2}>
<TestInstantiated id="2">Two</TestInstantiated>
</Case>
<Case expr={val === 3}>
<TestInstantiated id="3">Three</TestInstantiated>
</Case>
</Switch>
);
}
const elem = document.getElementById('thing');
ReactDOM.render(<TestSwitch/>, elem)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment