Skip to content

Instantly share code, notes, and snippets.

@tricoder42
Last active July 11, 2016 13:34
Show Gist options
  • Save tricoder42/7ede9c66e7e05ba911e0e5ac2e349d37 to your computer and use it in GitHub Desktop.
Save tricoder42/7ede9c66e7e05ba911e0e5ac2e349d37 to your computer and use it in GitHub Desktop.
Default props in React
// 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