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

Function HotSwap

src/py/reactpy/reactpy/testing/backend.py:199–210  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

197
198 @component
199 def HotSwap() -> Any:
200 # new displays will adopt the latest constructor and arguments
201 constructor, _set_constructor = use_state(lambda: constructor_ref.current)
202 set_constructor = use_callback(lambda new: _set_constructor(lambda _: new))
203
204 def add_callback() -> Callable[[], None]:
205 set_constructor_callbacks.add(set_constructor)
206 return lambda: set_constructor_callbacks.remove(set_constructor)
207
208 use_effect(add_callback)
209
210 return constructor()
211
212 def swap(constructor: Callable[[], Any] | None) -> None:
213 constructor = constructor_ref.current = constructor or (lambda: None)

Callers

nothing calls this directly

Calls 5

use_stateFunction · 0.90
use_callbackFunction · 0.90
use_effectFunction · 0.90
constructorFunction · 0.50
currentMethod · 0.45

Tested by

no test coverage detected