reactpy
reactpy copied to clipboard
Use props `dict` on components, rather than kwargs.
Current Situation
There's been a lot of growing pains in the fact that components have a significantly different interface than reactpy.html elements.
Developing certain parts of reactpy core and/or reactpy related utilities has been significantly more difficult due to this interface mismatch.
Proposed Actions
The new component interface should match the VDOM interface, and will look like this:
# `key=...` should be declared within props, identical to the `reactpy.html` interface.
my_component({"prop_1": True, "key": 123}, child_1, child_2)
As a part of this change, we should rename VdomAttributes to Props.
Do we retain args/kwargs?
We can handle @component function definitions a few ways. Some of these ways feel more similar to ReactJS, but have problems with Python type hints.
- Force all users to only use kwargs
- Retain type hints via PEP692
- Allow args/kwargs in function defs. Let Python unpacking operator handle the rest.
- This would break type hints, since args can't be defined within a TypedDict
- Force all users to define a
props: dictas their first parameter- However, forcing users to manually define a TypedDict for every component would be extremely inconvenient.
I'm personally leaning towards option 1.
More precisely the interface should conform to this protocol.
We can potentially retain type hints using this PEP https://peps.python.org/pep-0692/
I spent more thought on this issue while rewriting the docs.
@rmorshea We need to decide what we will do with the user's component function defs. See my updates above.
Note: we'll have to figure out how this will play work if the component function is a method.