Last active
July 11, 2016 13:34
-
-
Save tricoder42/7ede9c66e7e05ba911e0e5ac2e349d37 to your computer and use it in GitHub Desktop.
Default props in React
This file contains 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
// Is there any difference? (In performance for example?) | |
// A: Using default values in object destructuring | |
const A = ({ | |
value = "", | |
foo = "bar", | |
...props | |
}) => {}; | |
// B: Using defaultProps attribute | |
const B = (props) => {}; | |
B.defaultProps = { | |
value: "", | |
foo: "bar" | |
}; | |
// Wrong! Doesn't work, because React always provides `props` argument. If there's no props, it's empty object. | |
const C = (props = {value: "", foo: "bar"}) => {}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment