Skip to content

Commit 332ca75

Browse files
committed
better error for route state
1 parent ec1b633 commit 332ca75

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/reactpy_router/core.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,12 @@ class _RouteState:
150150

151151
def _use_route_state() -> _RouteState:
152152
route_state = use_context(_route_state_context)
153-
assert route_state is not None
153+
if route_state is None:
154+
raise RuntimeError(
155+
"ReactPy-Router was unable to find a route context. Are you "
156+
"sure this hook/component is being called within a router?"
157+
)
158+
154159
return route_state
155160

156161

0 commit comments

Comments
 (0)