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
{{ message }}
Repository navigation
Use props dict on components, rather than kwargs. #993
I did some prototyping, and learned it's currently not possible to use ParamSpec to provide type hints to a dictionary.
Given that components are functions, it feels natural for users to call them via the standard "python function interface" (AKA arguments within parenthesis)
Additionally, changing the reactpy.html interface to kwargs makes the HTML "read wrong", where all HTML properties are now declared at the bottom of the elements, making it almost unreadable to figure out what prop belongs to which element in deeply nested structures.
Unless the Python type hinting space makes some major changes, I think we're forced to continue down the road we've already paved. I've already raised the issue that the Python type hinting system has no way to "mutate" kwargs, so hopefully that gains some interest/traction.
Activity
rmorshea commentedon May 24, 2023
More precisely the interface should conform to this protocol.
Archmonger commentedon Jun 7, 2023
We can potentially retain type hints using this PEP https://peps.python.org/pep-0692/
Archmonger commentedon Jun 8, 2023
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.
rmorshea commentedon Jun 9, 2023
Note: we'll have to figure out how this will play work if the component function is a method.
Archmonger commentedon Feb 12, 2025
I did some prototyping, and learned it's currently not possible to use
ParamSpecto provide type hints to a dictionary.Given that components are functions, it feels natural for users to call them via the standard "python function interface" (AKA arguments within parenthesis)
Additionally, changing the
reactpy.htmlinterface to kwargs makes the HTML "read wrong", where all HTML properties are now declared at the bottom of the elements, making it almost unreadable to figure out what prop belongs to which element in deeply nested structures.Unless the Python type hinting space makes some major changes, I think we're forced to continue down the road we've already paved. I've already raised the issue that the Python type hinting system has no way to "mutate" kwargs, so hopefully that gains some interest/traction.
rmorshea commentedon Feb 17, 2025
A draft of the template strings PEP is currently in review so optimizing the interface may not be necessary anyways if that lands.
Archmonger commentedon Feb 17, 2025
Agreed, I recently made that same conclusion while talking about the
reactpy.htmldiscussion on Discord.