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
In simple use cases where there is no need for runtime props type checking (especially in functional components), making props optional could result in simpler code.
Detailed design
Stateful Components
When a component has no props declarations, all attributes passed by the parent are exposed in this.$props. Unlike declared props, they will NOT be exposed directly on this. In addition, in this case this.$attrs and this.$props will be pointing to the same object.
Nice thing about this is you can omit the <script> block altogether in a simple SFC:
To declare props for plain-function functional components, attach it to the function itself:
FunctionalComp.props={foo: Number}
Similar to stateful components, when props are declared, the props arguments will only contain the declared props - attributes received but not declared as props will be in the 3rd argument (attrs):
constFunctionalComp=(props,slots,attrs)=>{// `attrs` contains all received attributes except declared `foo`}FunctionalComp.props={foo: Number}
Regarding TS users, they won't be able to use this, would they?
About the runtime check, I know it's unrelated, but are we still leaving it for development only?
Summary
Make component
props
declaration optional.Basic example
Motivation
In simple use cases where there is no need for runtime props type checking (especially in functional components), making props optional could result in simpler code.
Detailed design
Stateful Components
When a component has no
props
declarations, all attributes passed by the parent are exposed inthis.$props
. Unlike declared props, they will NOT be exposed directly onthis
. In addition, in this casethis.$attrs
andthis.$props
will be pointing to the same object.Nice thing about this is you can omit the
<script>
block altogether in a simple SFC:Functional Components
This is based on plain-function functional components proposed in Functional and Async Component API Change.
To declare props for plain-function functional components, attach it to the function itself:
Similar to stateful components, when props are declared, the
props
arguments will only contain the declared props - attributes received but not declared as props will be in the 3rd argument (attrs
):For mode details on the new functional component signature, see Render Function API Change.
Drawbacks
N/A
Alternatives
N/A
Adoption strategy
The behavior is fully backwards compatible.
The text was updated successfully, but these errors were encountered: