remove cx.render
This commit is contained in:
159 files changed
+600
-658
No files matched your search
@@ -167,7 +167,7 @@ pub fn use_selector<I: 'static, O: Clone + PartialEq + 'static>
|
||||
init: impl FnMut(&I) -> O + 'static,
|
||||
) -> O {
|
||||
let selector = cx.use_hook(|| tracked.compute(init));
|
||||
selector.use_state(cx)
|
||||
selector.use_signal(cx)
|
||||
}
|
||||
|
||||
/// Selector state is state that is derived from tracked state
|
||||
@@ -188,7 +188,7 @@ impl<T, I> PartialEq for Selector<T, I> {
|
||||
|
||||
impl<T: Clone + PartialEq, I> Selector<T, I> {
|
||||
/// Read the Selector state and subscribe to updates
|
||||
pub fn use_state(&self, ) -> T {
|
||||
pub fn use_signal(&self, ) -> T {
|
||||
cx.use_hook(|| {
|
||||
let id = cx.scope_id();
|
||||
self.subscribers.borrow_mut().insert(id);
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
/// # }
|
||||
/// # fn Component(cx: Scope<Props>) -> Element {
|
||||
///
|
||||
/// let (data) = use_ref(|| {});
|
||||
/// let (data) = use_signal(|| {});
|
||||
///
|
||||
/// let handle_thing = move |_| {
|
||||
/// to_owned![data, cx.props.prop];
|
||||
|
||||
@@ -16,7 +16,7 @@ This is moderately efficient because the fields of the map are moved, but the da
|
||||
However, if you used similar approach with Dioxus:
|
||||
|
||||
```rust
|
||||
let (map, set_map) = use_state(|| HashMap::new());
|
||||
let (map, set_map) = use_signal(|| HashMap::new());
|
||||
set_map({
|
||||
let mut newmap = map.clone();
|
||||
newmap.set(key, value);
|
||||
@@ -38,9 +38,9 @@ Here's a fully-functional todo app using the use_map API:
|
||||
```rust
|
||||
static TodoList: Component = |cx| {
|
||||
let todos = use_map(|| HashMap::new());
|
||||
let input = use_ref(|| None);
|
||||
let input = use_signal(|| None);
|
||||
|
||||
cx.render(rsx!{
|
||||
rsx!{
|
||||
div {
|
||||
button {
|
||||
"Add todo"
|
||||
|
||||
@@ -14,7 +14,7 @@ use dioxus_core::prelude::*;
|
||||
/// fn Component() -> Element {
|
||||
/// let id = use_const(|| ComplexData(100));
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
/// rsx! {
|
||||
/// div { "{id.0}" }
|
||||
/// })
|
||||
/// }
|
||||
|
||||
@@ -56,7 +56,7 @@ use std::future::Future;
|
||||
/// });
|
||||
///
|
||||
///
|
||||
/// cx.render(rsx!{
|
||||
/// rsx!{
|
||||
/// button {
|
||||
/// onclick: move |_| chat_client.send(Action::Start),
|
||||
/// "Start Chat Service"
|
||||
|
||||
@@ -27,7 +27,7 @@ use crate::UseFutureDep;
|
||||
/// # use dioxus::prelude::*;
|
||||
/// #[component]
|
||||
/// fn Profile(id: usize) -> Element {
|
||||
/// let name = use_state(|| None);
|
||||
/// let name = use_signal(|| None);
|
||||
///
|
||||
/// // Only fetch the user data when the id changes.
|
||||
/// use_effect((id,), |(id,)| {
|
||||
|
||||
@@ -26,7 +26,7 @@ where
|
||||
F: Future<Output = T> + 'static,
|
||||
D: UseFutureDep,
|
||||
{
|
||||
let val = use_state(|| None);
|
||||
let val = use_signal(|| None);
|
||||
|
||||
let state = cx.use_hook(move || UseFuture {
|
||||
update: cx.schedule_update(),
|
||||
@@ -260,7 +260,7 @@ mod tests {
|
||||
|
||||
async fn app(cx: Scope<'_, MyProps>) -> Element {
|
||||
// should only ever run once
|
||||
let fut = use_future((), |_| async move {});
|
||||
let fut = use_future(|_| async move {});
|
||||
|
||||
// runs when a is changed
|
||||
let fut = use_future((&cx.props.a,), |(a,)| async move {});
|
||||
@@ -268,14 +268,14 @@ mod tests {
|
||||
// runs when a or b is changed
|
||||
let fut = use_future((&cx.props.a, &cx.props.b), |(a, b)| async move { 123 });
|
||||
|
||||
let a = use_future!(|| async move {
|
||||
let a = use_future(|| async move {
|
||||
// do the thing!
|
||||
});
|
||||
|
||||
let b = &123;
|
||||
let c = &123;
|
||||
|
||||
let a = use_future!(|b, c| async move {
|
||||
let a = use_future(|b, c| async move {
|
||||
let a = b + c;
|
||||
let blah = "asd";
|
||||
});
|
||||
|
||||
@@ -16,7 +16,7 @@ pub fn use_on_unmount<D: FnOnce() + 'static>(cx: &dioxus_core::ScopeState, destr
|
||||
/// use dioxus::prelude::*;
|
||||
///
|
||||
/// fn app() -> Element {
|
||||
/// let state = use_state(|| true);
|
||||
/// let state = use_signal(|| true);
|
||||
/// render! {
|
||||
/// for _ in 0..100 {
|
||||
/// h1 {
|
||||
@@ -38,7 +38,7 @@ pub fn use_on_unmount<D: FnOnce() + 'static>(cx: &dioxus_core::ScopeState, destr
|
||||
/// }
|
||||
///
|
||||
/// fn child_component() -> Element {
|
||||
/// let original_scroll_position = use_state(|| 0.0);
|
||||
/// let original_scroll_position = use_signal(|| 0.0);
|
||||
/// use_effect((), move |_| {
|
||||
/// to_owned![original_scroll_position];
|
||||
/// async move {
|
||||
|
||||
@@ -17,7 +17,7 @@ use std::{
|
||||
/// that initialized the hook will be marked as "dirty".
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let val = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val = use_signal(|| HashMap::<u32, String>::new());
|
||||
///
|
||||
/// // using `write` will give us a `RefMut` to the inner value, which we can call methods on
|
||||
/// // This marks the component as "dirty"
|
||||
@@ -68,7 +68,7 @@ use std::{
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let items = val.read().iter().map(|(k, v)| {
|
||||
/// cx.render(rsx!{ key: "{k}", "{v}" })
|
||||
/// rsx!{ key: "{k}", "{v}" })
|
||||
/// });
|
||||
///
|
||||
/// // collect into a Vec
|
||||
@@ -83,7 +83,7 @@ use std::{
|
||||
/// by simply calling `to_owned` or `clone`.
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let val = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val = use_signal(|| HashMap::<u32, String>::new());
|
||||
///
|
||||
/// cx.spawn({
|
||||
/// let val = val.clone();
|
||||
@@ -98,9 +98,9 @@ use std::{
|
||||
/// `to_owned!` macro to make it easier to write the above code.
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let val1 = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val2 = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val3 = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val1 = use_signal(|| HashMap::<u32, String>::new());
|
||||
/// let val2 = use_signal(|| HashMap::<u32, String>::new());
|
||||
/// let val3 = use_signal(|| HashMap::<u32, String>::new());
|
||||
///
|
||||
/// cx.spawn({
|
||||
/// to_owned![val1, val2, val3];
|
||||
@@ -111,7 +111,7 @@ use std::{
|
||||
/// })
|
||||
/// ```
|
||||
#[must_use]
|
||||
pub fn use_ref<T: 'static>(nitialize_refcell: impl FnOnce() -> T) -> &UseRef<T> {
|
||||
pub fn use_ref<T: 'static>(nitialize_refcell: impl FnOnce() -> T) -> Signal<T> {
|
||||
let hook = cx.use_hook(|| UseRef {
|
||||
update: cx.schedule_update(),
|
||||
value: Rc::new(RefCell::new(initialize_refcell())),
|
||||
@@ -196,7 +196,7 @@ impl<T> UseRef<T> {
|
||||
/// This method just does it for you automatically.
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let val = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val = use_signal(|| HashMap::<u32, String>::new());
|
||||
///
|
||||
///
|
||||
/// // use reborrowing
|
||||
@@ -216,7 +216,7 @@ impl<T> UseRef<T> {
|
||||
/// This method just does it for you automatically.
|
||||
///
|
||||
/// ```rust, no_run
|
||||
/// let val = use_ref(|| HashMap::<u32, String>::new());
|
||||
/// let val = use_signal(|| HashMap::<u32, String>::new());
|
||||
///
|
||||
///
|
||||
/// // use reborrowing
|
||||
|
||||
@@ -19,9 +19,9 @@ use std::{
|
||||
///
|
||||
/// ```ignore
|
||||
/// const Example: Component = |cx| {
|
||||
/// let count = use_state(|| 0);
|
||||
/// let count = use_signal(|| 0);
|
||||
///
|
||||
/// cx.render(rsx! {
|
||||
/// rsx! {
|
||||
/// div {
|
||||
/// h1 { "Count: {count}" }
|
||||
/// button { onclick: move |_| *count.modify() += 1, "Increment" }
|
||||
@@ -92,7 +92,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component() -> Element {
|
||||
/// let count = use_state(|| 0);
|
||||
/// let count = use_signal(|| 0);
|
||||
/// cx.spawn({
|
||||
/// let set_count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -119,7 +119,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component() -> Element {
|
||||
/// let value = use_state(|| 0);
|
||||
/// let value = use_signal(|| 0);
|
||||
///
|
||||
/// rsx!{
|
||||
/// Component {
|
||||
@@ -144,7 +144,7 @@ impl<T: 'static> UseState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component() -> Element {
|
||||
/// let value = use_state(|| 0);
|
||||
/// let value = use_signal(|| 0);
|
||||
///
|
||||
/// // to increment the value
|
||||
/// value.modify(|v| v + 1);
|
||||
@@ -185,7 +185,7 @@ impl<T: 'static> UseState<T> {
|
||||
/// # use dioxus_core::prelude::*;
|
||||
/// # use dioxus_hooks::*;
|
||||
/// fn component() -> Element {
|
||||
/// let value = use_state(|| 0);
|
||||
/// let value = use_signal(|| 0);
|
||||
///
|
||||
/// let as_rc = value.get();
|
||||
/// assert_eq!(as_rc.as_ref(), &0);
|
||||
@@ -207,7 +207,7 @@ impl<T: 'static> UseState<T> {
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// fn component() -> Element {
|
||||
/// let count = use_state(|| 0);
|
||||
/// let count = use_signal(|| 0);
|
||||
/// cx.spawn({
|
||||
/// let count = count.to_owned();
|
||||
/// async move {
|
||||
@@ -237,7 +237,7 @@ impl<T: Clone> UseState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let val = use_state(|| 0);
|
||||
/// let val = use_signal(|| 0);
|
||||
///
|
||||
/// val.with_mut(|v| *v = 1);
|
||||
/// ```
|
||||
@@ -269,7 +269,7 @@ impl<T: Clone> UseState<T> {
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust, ignore
|
||||
/// let val = use_state(|| 0);
|
||||
/// let val = use_signal(|| 0);
|
||||
///
|
||||
/// *val.make_mut() += 1;
|
||||
/// ```
|
||||
@@ -493,7 +493,7 @@ impl<T: Div<Output = T> + Copy> std::ops::DivAssign<T> for UseState<T> {
|
||||
fn api_makes_sense() {
|
||||
#[allow(unused)]
|
||||
fn app() -> Element {
|
||||
let val = use_state(|| 0);
|
||||
let val = use_signal(|| 0);
|
||||
|
||||
val.set(0);
|
||||
val.modify(|v| v + 1);
|
||||
|
||||
Reference in new issue
Block a user