Last active
March 30, 2016 07:26
-
-
Save SanderSpies/b793bcb065dd720a9072c696606b8aae to your computer and use it in GitHub Desktop.
React pattern matching braindumb
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const test = (props) => ( | |
<div> | |
{match(props).with( | |
(String) => <div>Should work {props}</div>, | |
({bar = '1', test: {x = false}}) => <div>Super cool {bar}</div>, | |
({bar = '5', test: {y = true}}) => <div>Mega cool {test.y} {y}</div>, | |
([a = 3, {x = 4}, z]) => | |
<nesting> | |
{match(z).with( | |
({bar = '5', test: {y = true}}) => | |
<div> | |
Foobar {a} {test.x} {z} | |
</div> | |
)} | |
</nesting> | |
)} | |
</div> | |
); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This should also be supported:
{foo = String, bar = Boolean})