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
We need to set up the ability to set default values for properties passed into components. These defaults will only be utilized in cases where a developer has not supplied a value to any properties which have defaults defined.
Utilizing this should be similar to defining prop types; on a component, an object that defines default prop values can be created which will automatically get looked up by getDefaultProps. The Component code will automatically take care of the work of checking for the default values and using them when no value has been passed in.
Example:
importComponentfrom'ember-component';importhbsfrom'htmlbars-inline-precompile';importPropTypesfrom'prop-types';exportdefaultComponent.extend({defaultProps: {bar: 5,greeting: 'Hello, ',name: 'smart and attractive developer'}propTypes: {bar: PropTypes.number,greeting: PropTypes.string,name: PropTypes.string},layout: hbs`{{greeting}}{{name}}! You are looking like {{bar}} million major currency units today!`});
Under the hood, we will need to make additions to our Component initializer to set the default values from defaultProps to their corresponding properties on the component itself.
The text was updated successfully, but these errors were encountered:
For maximum perf reasons the props validations are only run in dev builds (we don't ship the validators in prod builds). For this reason we cannot set defaults when a prop is invalid.
I think we should mirror the React pattern here, which is to set a default prop when a prop is undefined during initialization of component.
On Tue, May 23, 2017 at 17:28 Dan Hedgecock ***@***.***> wrote:
For maximum perf reasons the props validations are only run in dev builds
(we don't ship the validators in prod builds). For this reason we cannot
set defaults when a prop is invalid.
I think we should mirror the React pattern here, which is to set a default
prop when a prop is undefined during initialization of component.
Thoughts?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#4 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAOWfSzo7ncx8YveklVPyKvjKrCO_YpCks5r824EgaJpZM4NkBAr>
.
We need to set up the ability to set default values for properties passed into components. These defaults will only be utilized in cases where a developer has not supplied a value to any properties which have defaults defined.
Utilizing this should be similar to defining prop types; on a component, an object that defines default prop values can be created which will automatically get looked up by
getDefaultProps
. The Component code will automatically take care of the work of checking for the default values and using them when no value has been passed in.Example:
Under the hood, we will need to make additions to our Component initializer to set the default values from
defaultProps
to their corresponding properties on the component itself.The text was updated successfully, but these errors were encountered: