File tree Expand file tree Collapse file tree 2 files changed +27
-0
lines changed
Expand file tree Collapse file tree 2 files changed +27
-0
lines changed Original file line number Diff line number Diff line change @@ -146,6 +146,12 @@ def use_effect(
146146 Returns:
147147 If not function is provided, a decorator. Otherwise ``None``.
148148 """
149+ if asyncio .iscoroutinefunction (function ):
150+ raise TypeError (
151+ "`use_effect` does not support async functions. "
152+ "Use `use_async_effect` instead."
153+ )
154+
149155 hook = HOOK_STACK .current_hook ()
150156 dependencies = _try_to_infer_closure_values (function , dependencies )
151157 memoize = use_memo (dependencies = dependencies )
Original file line number Diff line number Diff line change @@ -1287,3 +1287,24 @@ def bad_cleanup():
12871287 await layout .render ()
12881288 component_hook .latest .schedule_render ()
12891289 await layout .render () # no error
1290+
1291+
1292+ def test_use_effect_exception_on_async_function ():
1293+ @reactpy .component
1294+ def ComponentWithBadEffect ():
1295+ @reactpy .hooks .use_effect
1296+ async def bad_effect ():
1297+ pass
1298+
1299+ return reactpy .html .div ()
1300+
1301+ with assert_reactpy_did_log (
1302+ match_error = "does not support async functions" ,
1303+ error_type = TypeError ,
1304+ ):
1305+
1306+ async def run_test ():
1307+ async with reactpy .Layout (ComponentWithBadEffect ()) as layout :
1308+ await layout .render ()
1309+
1310+ asyncio .run (run_test ())
You can’t perform that action at this time.
0 commit comments