What are the disadvantages of this approach compared to using defaultProps ?
In your specific code example; none, because you only use one option once. However, imagine larger applications where some support is used in many places, it would be very tedious to manually determine the "fallback value" if the value is false.
Also imagine that suddenly you decide to change this value to something else; You will need to go through your entire component and update wherever this feature is used. This would make him prone to errors and errors.
Another problem with your approach is that if you really do , you want certain support to be false, like null or 0 . Then your state will fail, and a βfallback valueβ will be used instead.
Thus, the use of defaultProps simplifies the management of your props and becomes more comprehensive and manageable.
By the way, for your reference, the logical expression you are using is called Short Circuit Evaluation .
Chris source share