Adds support for property binding over attribute binding #93
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed changes
This pull request adds supports for a React Component's props to by passed by a Custom Element's Properties. This allows for complex objects, reference types, and even functions to be passed to a React Component without being serialized.
This is done by making 2 small changes + a new example under
examples/property-binding.html
:Motivation
Limitations of Attributes
remount is a fantastic library, but unfortunately it requires that props passed to React be serialized to JSON before being passed.
Accepting props as a JSON object is great because you can account for complex objects and don't have to deal with the limitation that attributes must be lower-case.
This is very useful on its own, but unfortunately makes it impossible to pass certain data types, such as:
HTMLElement
,Set
, etc.Enter Properties
An Element's Properties are accessed from the JavaScript end. They can be read and written using a JavaScript reference to the Element as an object.
Obviously, one could access the properties of a custom element by doing
document.getElementById()
or something else, but that is a chore and doesn't make sense for the declarative nature of a Web Component.Unfortunately, this isn't something that we can solve with native HTML, but this is something that a variety of web frameworks have already solved.
How other web frameworks do it