You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Do you want to request a feature or to report a bug
Both(Either of them). Report a Bug/Feature. Not sure if this would be a potential bug. This could be a feature when we can explicitly define a property via .defaultProps
What is current behavior (Re-produce) ?
props.derivedState is an object whose one of the property is randomString. It cannot be initialized i.e. set to default value using .defaultProps in case when I am not setting randomString in dereivedState object.(intentionally to test)
Basically object/array(or any other primitive element) can be set to default as per defaultProps functionality. But when setting property of an object, I am facing this issue that I cannot initialize it.
// in app.js<div><h1>{this.props.derivedState.randomString}</h1>{/* PRINTS NOTHING (In case : if randomString was not defined/set as property in object derivedState) */}</div>...App.defaultProps={derivedState: {randomString: "Stranger"}};
What is the expected behavior?
By doing this,
// in app.js<div><h1>{this.props.derivedState.randomString}</h1>{/* PRINTS STRANGER (In case : if randomString was not defined/set as property in object derivedState) */}</div>...App.defaultProps={derivedState: {randomString: "Stranger"}};
the props.derivedState's property(i.e. randomString) can be set to default value to "Stranger".
I experienced that when instead of not setting randomString I completely didn't passed attribute derivedState(which is prop) which resulted in printing "Stranger" (randomString property ). This is reproduced in use case 2
The text was updated successfully, but these errors were encountered:
meetzaveri
changed the title
Default Proptypes : Not able to set default proptypes for object's property(s)
Default Proptypes : Not able to set default proptypes for object's property(s) if not defined
Sep 12, 2018
meetzaveri
changed the title
Default Proptypes : Not able to set default proptypes for object's property(s) if not defined
Default Proptypes : Not able to set default proptypes for object's property(s) if property is not defined
Sep 12, 2018
meetzaveri
changed the title
Default Proptypes : Not able to set default proptypes for object's property(s) if property is not defined
Default Proptypes : Not able to set default prop value for object's property(s) if property is not defined
Sep 12, 2018
Do you want to request a feature or to report a bug
Both(Either of them). Report a Bug/Feature. Not sure if this would be a potential bug. This could be a feature when we can explicitly define a property via
.defaultProps
What is current behavior (Re-produce) ?
props.derivedState
is an object whose one of the property israndomString
. It cannot be initialized i.e. set to default value using.defaultProps
in case when I am not settingrandomString
indereivedState
object.(intentionally to test)Basically object/array(or any other primitive element) can be set to default as per
defaultProps
functionality. But when setting property of an object, I am facing this issue that I cannot initialize it.What is the expected behavior?
By doing this,
the
props.derivedState
's property(i.e.randomString
) can be set to default value to "Stranger".Use cases (Codesandbox links):
I experienced that when instead of not setting
randomString
I completely didn't passed attributederivedState
(which is prop) which resulted in printing "Stranger" (randomString
property ). This is reproduced in use case 2The text was updated successfully, but these errors were encountered: