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
Both examples show how the behaviour of the attributes should be left with the child when dictating what attributes shoud be rendered. You can either do a and rest approach or explcititly name attributes to pass onto element.
The original all props/attrs will be rendered as attributes, which adds polution to the DOM especially with attributes that are array's/objects/functions/symbols.
The text was updated successfully, but these errors were encountered:
blake-newman
changed the title
Remove attribue merging for functioal components with no prop definition
Remove attribute merging for functional components with no prop definition
Jan 29, 2018
What problem does this feature solve?
Currently when using functional components without
prop
definition, all attributes will be rendered when usingJSX spread
.This is because the
context.data.attrs
remain after they are merged.Current
Usage:
<Example type="blue" fill={true} class="extra-class" aria-label="I'm a label" />
Implementation:
Output:
<button fill="true" type="blue" class="extra-class button--fill button--blue" aria-label="I'm a label" />
What does the proposed API look like?
It should be explicit what attributes to render to dom when using a functional component with no prop definition.
With fix
delete data.attrs
Explicitly passing attributes
You can use spread notation to get all remaining
attrs
, and replacing thedata.attrs
objectUsage:
<Example type="blue" fill={true} class="extra-class" aria-label="I'm a label" />
Implementation:
Output:
<button class="extra-class button--fill button--blue" aria-label="I'm a label" />
Explicitly passing attributes 2
Usage:
<Example type="blue" fill={true} class="extra-class" formtarget="id" dummy-attr="lol" />
Implementation:
Output:
<button class="extra-class button--fill button--blue" formtarget="id" />
Conclusion
Both examples show how the behaviour of the attributes should be left with the child when dictating what attributes shoud be rendered. You can either do a
and rest
approach or explcititly name attributes to pass onto element.The original all props/attrs will be rendered as attributes, which adds polution to the DOM especially with attributes that are array's/objects/functions/symbols.
The text was updated successfully, but these errors were encountered: