fix use hooks with impl signals

This commit is contained in:
Evan Almloff 2024-01-23 10:09:02 -06:00
parent 51d7133ca5
commit c51badf07b
3 changed files with 6 additions and 6 deletions

View file

@ -1,6 +1,6 @@
use dioxus_core::prelude::{consume_context, provide_context, spawn, use_hook};
use dioxus_core::Task;
use dioxus_signals::{CopyValue, Signal};
use dioxus_signals::*;
pub use futures_channel::mpsc::{UnboundedReceiver, UnboundedSender};
use std::future::Future;
@ -71,7 +71,7 @@ where
G: FnOnce(UnboundedReceiver<M>) -> F,
F: Future<Output = ()> + 'static,
{
let coroutine = use_hook(|| {
let mut coroutine = use_hook(|| {
provide_context(Coroutine {
needs_regen: Signal::new(true),
tx: CopyValue::new(None),
@ -81,12 +81,12 @@ where
// We do this here so we can capture data with FnOnce
// this might not be the best API
if *coroutine.needs_regen.read() {
if *coroutine.needs_regen.peek() {
let (tx, rx) = futures_channel::mpsc::unbounded();
let task = spawn(init(rx));
coroutine.tx.set(Some(tx));
coroutine.task.set(Some(task));
coroutine.needs_regen.set_untracked(false);
coroutine.needs_regen.set(false);
}
coroutine

View file

@ -3,7 +3,7 @@ use dioxus_core::{
prelude::{spawn, use_hook},
ScopeState, Task,
};
use dioxus_signals::{use_effect, use_signal, Effect, Signal};
use dioxus_signals::*;
use futures_util::{future, pin_mut, FutureExt};
use std::{any::Any, cell::Cell, future::Future, pin::Pin, rc::Rc, sync::Arc, task::Poll};

View file

@ -3,7 +3,7 @@ use dioxus_core::{
prelude::{spawn, use_hook},
ScopeState, Task,
};
use dioxus_signals::{use_effect, use_signal, Effect, Signal};
use dioxus_signals::*;
use futures_util::{future, pin_mut, FutureExt};
use std::{any::Any, cell::Cell, future::Future, pin::Pin, rc::Rc, sync::Arc, task::Poll};