Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.