Skip to content

Commit b9595ff

Browse files
committed
improve docstring
1 parent a4fc2f5 commit b9595ff

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/py/reactpy/reactpy/core/_life_cycle_hook.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,10 +64,13 @@ class LifeCycleHook:
6464
# and save state or add effects
6565
current_hook().use_state(lambda: ...)
6666
67-
async def effect():
68-
yield
67+
async def start_effect():
68+
...
6969
70-
current_hook().add_effect(effect)
70+
async def stop_effect():
71+
...
72+
73+
current_hook().add_effect(start_effect, stop_effect)
7174
finally:
7275
await hook.affect_component_did_render()
7376
@@ -140,7 +143,12 @@ def add_effect(
140143
start_effect: Callable[[], Awaitable[None]],
141144
clean_effect: Callable[[], Awaitable[None]],
142145
) -> None:
143-
"""Add an effect to this hook"""
146+
"""Add an effect to this hook
147+
148+
Effects are started when the component is done renderig and cleaned up when the
149+
component is removed from the layout. Any other actions (e.g. re-running the
150+
effect if a dependency changes) are the responsibility of the effect itself.
151+
"""
144152
self._effect_startups.append(start_effect)
145153
self._effect_cleanups.append(clean_effect)
146154

0 commit comments

Comments
 (0)