React.js - default prop is not used with `null` is passed

前端 未结 3 636
太阳男子
太阳男子 2020-12-30 19:47

I have default props in my React component:

PropertyTitleLabel.defaultProps = {
    bedrooms: 1,
    propertyType: \'flat\'
};
PropertyTitleLabel.propTypes =         


        
3条回答
  •  悲&欢浪女
    2020-12-30 20:25

    • undefined = nothing.
    • null = something that hints "nothing".

    undefined doesn't exist in reality. null however does exist. This means undefined won't pass a prop value as you cannot pass something which doesn't exist. Since null is not nothing, but rather is something which only hints at nothing, it passes in props.

提交回复
热议问题