Skip to content

Instantly share code, notes, and snippets.

@unrevised6419
Last active December 6, 2024 19:39
Show Gist options
  • Save unrevised6419/1068a5186913bd40c1d4a0e84e124c54 to your computer and use it in GitHub Desktop.
Save unrevised6419/1068a5186913bd40c1d4a0e84e124c54 to your computer and use it in GitHub Desktop.
React startTransition wrapper
"use client";
import { startTransition, type TransitionFunction } from "react";
function useStartTransition<Args extends unknown[]>(
cb: (...args: Args) => ReturnType<TransitionFunction>,
) {
return (...args: Args) => startTransition(() => cb(...args));
}
function App() {
const setFilter = useStartTransition((something: string) => {
// Call anything here that needs to be transitioned
console.log(something);
});
return <button onClick={() => setFilter("transitioning")}>Transition</button>;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment