Skip to content

Commit 3bd6c84

Browse files
committed
Fix error for bad use effect usage
1 parent cd55de6 commit 3bd6c84

File tree

1 file changed

+6
-5
lines changed

1 file changed

+6
-5
lines changed

src/reactpy/core/hooks.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,18 +145,19 @@ def use_effect(
145145
Returns:
146146
If not function is provided, a decorator. Otherwise ``None``.
147147
"""
148-
if inspect.iscoroutinefunction(function):
149-
raise TypeError(
150-
"`use_effect` does not support async functions. "
151-
"Use `use_async_effect` instead."
152-
)
153148

154149
hook = HOOK_STACK.current_hook()
155150
dependencies = _try_to_infer_closure_values(function, dependencies)
156151
memoize = use_memo(dependencies=dependencies)
157152
cleanup_func: Ref[_EffectCleanFunc | None] = use_ref(None)
158153

159154
def decorator(func: _SyncEffectFunc) -> None:
155+
if inspect.iscoroutinefunction(func):
156+
raise TypeError(
157+
"`use_effect` does not support async functions. "
158+
"Use `use_async_effect` instead."
159+
)
160+
160161
async def effect(stop: asyncio.Event) -> None:
161162
# Since the effect is asynchronous, we need to make sure we
162163
# always clean up the previous effect's resources

0 commit comments

Comments
 (0)