What is the difference between defaultProps and default parameter values?
Answer
Both provide fallback values for component props, but they work differently. defaultProps: a static property on the component class or function that React merges with the passed props before rendering. Deprecated for function components in React 18.3. MyComponent.defaultProps = { color: "blue", size: 16 };. Pros: works in class components; was the original React way. Cons: the defaults are defined separately from the component signature, making them less visible; deprecated for function components. Default parameter values: standard JavaScript destructuring defaults in the function signature. function Button({ color = "blue", size = 16, onClick }) { ... }. Pros: co-located with props; type inference works better in TypeScript; more idiomatic modern JavaScript; works for function components without any React-specific API. Cons: does not work in class components. Recommendation: always use JavaScript default parameter values for function components — they are cleaner, more visible, and better supported by tooling. Use defaultProps only if maintaining legacy class components.
Previous
What is the reconciliation algorithm and Fiber?
Next
What is the difference between findDOMNode and ref?