From 64881fd9518ce45e5ff2d0ba226960ef6b65e168 Mon Sep 17 00:00:00 2001 From: ealmloff Date: Thu, 5 Jan 2023 13:05:04 -0600 Subject: [PATCH] improve error message when a user tried to use nested hooks (#723) --- packages/core/src/scopes.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/core/src/scopes.rs b/packages/core/src/scopes.rs index b0189cbde..02d68a4ff 100644 --- a/packages/core/src/scopes.rs +++ b/packages/core/src/scopes.rs @@ -556,7 +556,7 @@ impl<'src> ScopeState { #[allow(clippy::mut_from_ref)] pub fn use_hook(&self, initializer: impl FnOnce() -> State) -> &mut State { let cur_hook = self.hook_idx.get(); - let mut hook_list = self.hook_list.borrow_mut(); + let mut hook_list = self.hook_list.try_borrow_mut().expect("The hook list is already borrowed: This error is likely caused by trying to use a hook inside a hook which violates the rules of hooks."); if cur_hook >= hook_list.len() { hook_list.push(self.hook_arena.alloc(initializer()));