mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-22 16:31:10 +00:00
Wait for global state to be populated
This commit is contained in:
parent
1a0acca3a0
commit
5482f8758e
1 changed files with 8 additions and 1 deletions
|
@ -41,6 +41,7 @@ use leptos::{
|
||||||
use leptos_meta::{provide_meta_context, *};
|
use leptos_meta::{provide_meta_context, *};
|
||||||
use leptos_router::{Route, Router, Routes};
|
use leptos_router::{Route, Router, Routes};
|
||||||
use reqwest::Client;
|
use reqwest::Client;
|
||||||
|
use std::{thread::sleep, time::Duration};
|
||||||
|
|
||||||
// https://book.leptos.dev/15_global_state.html
|
// https://book.leptos.dev/15_global_state.html
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -51,7 +52,13 @@ pub struct GlobalState {
|
||||||
|
|
||||||
impl GlobalState {
|
impl GlobalState {
|
||||||
pub fn api_client() -> ApiClient {
|
pub fn api_client() -> ApiClient {
|
||||||
use_context::<RwSignal<GlobalState>>()
|
let mut global_state = use_context::<RwSignal<GlobalState>>();
|
||||||
|
// Wait for global state to be populated (only needed on instance_details for some reason)
|
||||||
|
while global_state.is_none() {
|
||||||
|
sleep(Duration::from_millis(10));
|
||||||
|
global_state = use_context::<RwSignal<GlobalState>>();
|
||||||
|
}
|
||||||
|
global_state
|
||||||
.expect("global state is provided")
|
.expect("global state is provided")
|
||||||
.get_untracked()
|
.get_untracked()
|
||||||
.api_client
|
.api_client
|
||||||
|
|
Loading…
Reference in a new issue