简单React
0 1

请解释: React 的getDefaultProps?它有什么作用 是什么?

【概念释义】

getDefaultProps 是类组件静态方法,为 props 提供默认值。当父组件未传入某 prop 时,React 合并默认值。注意:仅对 undefined 生效,传 null 不会回退默认。

【基础使用】

jsx
class Button extends React.Component {
  static defaultProps = { type: "button", size: "md" };
  "qb-hl-comment">// 旧写法:Button.defaultProps = { type: "button" };
  render() {

登录查看完整 1188

回答讨论

暂无讨论,登录后可抢先发言

本题库更多题目(50)