mirror of
https://github.com/leptos-rs/book.git
synced 2025-12-27 07:35:38 -05:00
fix example code on resources
This commit is contained in:
@@ -94,56 +94,6 @@ async fn load_data(value: i32) -> i32 {
|
||||
value * 10
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
// this count is our synchronous, local state
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
// tracks `count`, and reloads by calling `load_data`
|
||||
// whenever it changes
|
||||
let async_data = LocalResource::new(move || load_data(count.get()));
|
||||
|
||||
// a resource will only load once if it doesn't read any reactive data
|
||||
let stable = LocalResource::new(|| load_data(1));
|
||||
|
||||
// we can access the resource values with .get()
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
use leptos::prelude::*;
|
||||
|
||||
// Here we define an async function
|
||||
// This could be anything: a network request, database read, etc.
|
||||
// Here, we just multiply a number by 10
|
||||
async fn load_data(value: i32) -> i32 {
|
||||
// fake a one-second delay
|
||||
TimeoutFuture::new(1_000).await;
|
||||
value * 10
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
// this count is our synchronous, local state
|
||||
let (count, set_count) = signal(0);
|
||||
|
||||
// tracks `count`, and reloads by calling `load_data`
|
||||
// whenever it changes
|
||||
let async_data = LocalResource::new(move || load_data(count.get()));
|
||||
|
||||
// a resource will only load once if it doesn't read any reactive data
|
||||
let stable = LocalResource::new(|| load_data(1));
|
||||
|
||||
// we can access the resource values with .get()
|
||||
use gloo_timers::future::TimeoutFuture;
|
||||
use leptos::prelude::*;
|
||||
|
||||
// Here we define an async function
|
||||
// This could be anything: a network request, database read, etc.
|
||||
// Here, we just multiply a number by 10
|
||||
async fn load_data(value: i32) -> i32 {
|
||||
// fake a one-second delay
|
||||
TimeoutFuture::new(1_000).await;
|
||||
value * 10
|
||||
}
|
||||
|
||||
#[component]
|
||||
pub fn App() -> impl IntoView {
|
||||
// this count is our synchronous, local state
|
||||
|
||||
Reference in New Issue
Block a user