Fix creating signals in effects

This commit is contained in:
Evan Almloff committed 2023-08-21 14:42:56 -05:00
1 parent d8704a0447
commit 38274da3ee
3 files changed
+19 -9

No files matched your search

+2
View File
@@ -54,6 +54,7 @@ pub fn use_effect_with_dependencies<D: Dependency>(
/// Effects allow you to run code when a signal changes. Effects are run immediately and whenever any signal it reads changes.
#[derive(Copy, Clone, PartialEq)]
pub struct Effect {
pub(crate) source: ScopeId,
pub(crate) callback: CopyValue<Box<dyn FnMut()>>,
}
@@ -73,6 +74,7 @@ impl Effect {
/// The signal will be owned by the current component and will be dropped when the component is dropped.
pub fn new(callback: impl FnMut() + 'static) -> Self {
let myself = Self {
source: current_scope_id().expect("in a virtual dom"),
callback: CopyValue::new(Box::new(callback)),
};