v1.37.0
React Suspense
import { List, Toast, showToast, ActionPanel, Action, Icon, popToRoot } from "@raycast/api";
import { useState, useCallback } from "react";
import * as twitter from "./oauth/twitter";
// a hook that suspends until a promise is resolved
import { usePromise } from "./suspense-use-promise";
const promise = async (search: string) => {
try {
await twitter.authorize();
return await twitter.fetchItems(search);
} catch (error) {
console.error(error);
showToast({ style: Toast.Style.Failure, title: String(error) });
return [];
}
};
export default function Command() {
const [search, setSearch] = useState("");
const items = usePromise(promise, [search]);
const logout = useCallback(() => {
twitter.logout();
popToRoot();
}, []);
const actionPanel = (
<ActionPanel>
<Action title="Logout" onAction={logout} />
</ActionPanel>
);
// no need to set the `isLoading` prop, Raycast will set it automatically
// until the React application isn't suspended anymore
return (
<List onSearchTextChange={setSearch} throttle>
{items.map((item) => {
return (
<List.Item key={item.id} id={item.id} icon={Icon.TextDocument} title={item.title} actions={actionPanel} />
);
})}
</List>
);
}Last updated

