useAsync and useSuspense
suspend the execution of a render until the resolution of an asynchronous process
useAsync
import { useAsync } from "atomico";
const getUser = (userId) => fetch(`users/${userId}`).then((res) => res.json());
function component({ userId }) {
const user = useAsync(getUser, [userId]);
return (
<host>
<h1>name: {user.name}</h1>
</host>
);
}
component.props = { userId: Number }import { Props, useAsync } from "atomico";
const getUser = (userId: number): Promise<{ name: string }> =>
fetch(`users/${userId}`).then((res) => res.json());
function component({ userId }: Props<typeof component>) {
const user = useAsync(getUser, [userId]);
return (
<host>
<h1>name: {user.name}</h1>
</host>
);
}
component.props = { userId: Number };useSuspense
Last updated
Was this helpful?
