S
SolidJS7mo ago
alloyed

1. arguments to useTransition() 2. measuring async updates

quicker one this time :) 1. looking at the official docs for useTransition:
import { useTransition } from "solid-js";



function useTransition(): [

pending: () => boolean,

startTransition: (fn: () => void) => Promise<void>

];
// example
start(() => setSignal(newValue), () => /* transition is done */)
import { useTransition } from "solid-js";



function useTransition(): [

pending: () => boolean,

startTransition: (fn: () => void) => Promise<void>

];
// example
start(() => setSignal(newValue), () => /* transition is done */)
start is taking two arguments in the example, but only takes one in the typescript. Is the second argument just undocumented? something like
function useTransition(): [
pending: () => boolean,
startTransition: (applyTransition: () => void, onTransitionComplete: () => void) => Promise<void> // promise returns when transition completes as well
];
function useTransition(): [
pending: () => boolean,
startTransition: (applyTransition: () => void, onTransitionComplete: () => void) => Promise<void> // promise returns when transition completes as well
];
and I guess is there a preference between using the second arg and the promise assuming they both measure the same thing? 2. This question is a bit larger than just async but it's coming up because I want to be able to measure the impact using async has on the latency of my app. The most straightforward way to do that is to add a profiler mark before solidjs has done any rendering, and then add a profiler mark after solidjs is "done". the thing is, I'm not sure how to define "done" or if there is even an API for it! My naive guess would be when the effect stack has "cleared" ie, we are at 0 render effects or effects, so the only thing that could cause an update would be an external/DOM event, but I don't see any way to track that just based on the public API.
2 Replies
alloyed
alloyed7mo ago
startTransition no longer takes callback as a second argument

Instead it returns a promise you can await. This works better for chaining sequences of actions.

const [start, isPending] = useTransition();

start(() => doSomething()).then(() => allDone());
startTransition no longer takes callback as a second argument

Instead it returns a promise you can await. This works better for chaining sequences of actions.

const [start, isPending] = useTransition();

start(() => doSomething()).then(() => allDone());
gotcha, so the answer to #1 is "the type signature is right the docs are wrong", cool
Want results from more Discord servers?
Add your server
More Posts
Can't run npm installHowdy y'all, I was trying to use the installer for solid start, and I chose the AuthJS option duringHow do we configure babel proposal decorators with Solid's vite plugin?I've got this Stackblitz: https://stackblitz.com/edit/solidjs-templates-wyjc1i?file=index.html,src%Can't build SolidStart after updating packagesAfter updating packages, I can't build project both locally and on vercel. I can't find anything relhow to trigger the fetcher in createResource if there are multiple signal values?hello, newbie here. In the document, it could be create a Memo as a group of signals as following. WNicest way of having computed properties in a store?I'm trying to model my store in a concise way, I want to have some base properties, and some computTypesafe way to render conditionally based on whether array has zero, one or many elements?Given an array with one or more elements, the idea is to display different UIs. With React, this canHow to implement JWT authentication in SolidJS, without SolidStart?I'm currently learning SolidJS for a SPA app with JWT-based auth. Right now I'm trying to implement Attempting to access a stale value from <Show>...Hi peeps, I have a rather complex application with lots of stores and recently have this issue. ``solidJS equivalent of react's cloneElementI'm trying to convert a react component that uses cloneElement to a solidJS component. I've briefly How to properly memoize children?I have a small reactivity puzzle that I'm a little stumped on. I'm not sure if I just haven't struct