MCPcopy Index your code
hub / github.com/reactive-python/reactpy / component

Function component

src/py/reactpy/reactpy/core/component.py:10–31  ·  view source on GitHub ↗

A decorator for defining a new component. Parameters: function: The component's :meth:`reactpy.core.proto.ComponentType.render` function.

(
    function: Callable[..., ComponentType | VdomDict | str | None]
)

Source from the content-addressed store, hash-verified

8
9
10def component(
11 function: Callable[..., ComponentType | VdomDict | str | None]
12) -> Callable[..., Component]:
13 """A decorator for defining a new component.
14
15 Parameters:
16 function: The component's :meth:`reactpy.core.proto.ComponentType.render` function.
17 """
18 sig = inspect.signature(function)
19
20 if "key" in sig.parameters and sig.parameters["key"].kind in (
21 inspect.Parameter.KEYWORD_ONLY,
22 inspect.Parameter.POSITIONAL_OR_KEYWORD,
23 ):
24 msg = f"Component render function {function} uses reserved parameter 'key'"
25 raise TypeError(msg)
26
27 @wraps(function)
28 def constructor(*args: Any, key: Any | None = None, **kwargs: Any) -> Component:
29 return Component(function, key, args, kwargs, sig)
30
31 return constructor
32
33
34class Component:

Callers 1

model_streamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected