SolidJSS
SolidJSโ€ข2y agoโ€ข
6 replies
KokoNeot

order of reactivity

Hi, i have this component

export default function Orders() {

    const [displayMode, setDisplayMode] = createSignal("customer")
    const [orders] = createResource(displayMode, getOrders)


    const switchDisplayMode = () => {
        setDisplayMode(displayMode() == "customer" ? "product" : "customer")
        console.log(displayMode(), orders.loading)
    }


    return <div class="container mx-auto">
        <div class="h-30 py-4 [&>*]:mx-2">
            <Button variant="contained" color="success" href="/orders/new">New order</Button>
            <Button variant="contained" color="primary" onClick={switchDisplayMode}>{displayMode() == "customer" ? "Display by products" : "Display by customers"}</Button>
        </div>

        <Show when={displayMode() == "customer" && !orders.loading}>
            <ByCustomerTable orders={orders()} />
        </Show>

        <Show when={displayMode() == "product" && !orders.loading}>
            <ByProductTable orders={orders()} />
        </Show>

    </div>
}


when i click the button i want to change display mode, based on display mode i want to fetch new data and then display it in the show tag

the issue is, when the displaymode changes first it triggers the shows and that errors out because each show is anticipating different data structure which is not fetched yet
Was this page helpful?