Can I Pass `createAsync()` a Signal?
I'm building an analytics dashboard with the Plausible API.
Their API let's you set the time period for the data you're requesting by appending a period value to your URL string like
I want to dynamically change this period value when clicking buttons (e.g., "12mo", "month", "7day", etc). So my server function looks like this: Here's my question. I'm using
&period=6m0
.I want to dynamically change this period value when clicking buttons (e.g., "12mo", "month", "7day", etc). So my server function looks like this: Here's my question. I'm using
cache
, createAsync()
, and the load()
function to render the initial data for the page. I'm setting a hard coded value for the first load. But after that I want to let users change the time period by clicking buttons.
I've pasted my design pattern below. Is it a good pattern? I asking because I periodically get a page flicker or refresh when I click the buttons and I can't figure out why.
Thank you!12 Replies
This is a good design. The flicker is likely because
metrics
will trigger suspense each time it refetches, since setRange
isn't wrapped in startTransition
Thank you!
Is there a simple way to show me how to use startTransition?
startTransition(() => setRange(newRange))
And that should fix the flicker?
Should do
Brilliant!
Thank you.
It works since the
createAsync
will then re-run within that transition, so the UI will see the stale value rather than suspendingThat works great!
Is this the extent of the docs on
startTransition
?
https://docs.solidjs.com/reference/reactive-utilities/start-transition#starttransitionuseTransition
elaborates a bit more but yeah
Could be useful to have a page dedicated to Transitions themselvesHaha. For people like myself who are still learning, definitely!
Oh the solid tutorial has a section on them actually
Oh cool. I'll dig through that. Thanks!
Just read about it. I get it now. That's a cool addition to the tool belt. Thanks again!