Created
May 11, 2018 15:06
-
-
Save jmcmaster/2fd3689a556f14e4221e1a56aeb238fa to your computer and use it in GitHub Desktop.
Named Params Destructuring
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
| function display({data, error, loading}) { | |
| if (loading) { | |
| return "Loading..."; | |
| } | |
| if (error) { | |
| return error.message; | |
| } | |
| return `Hello ${data.name}`; | |
| } | |
| const res1 = display({loading: true}) | |
| const res2 = display({error: {message: "this is an error"}}) | |
| const res3 = display({data: {name: 'World'}}) | |
| console.log(res1, res2, res3); | |
| // ------------------ | |
| function sayHi([first, last]) { | |
| return `Hi ${first}` | |
| } | |
| const res4 = sayHi(['Jason', 'McMaster']) | |
| console.log(res4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment