From 1f5b7384aaa4634451d10bf372b0c691f8cddf36 Mon Sep 17 00:00:00 2001 From: mathieudutour Date: Tue, 18 Jul 2023 19:19:10 +0200 Subject: [PATCH] Docs: Use export for examples --- docs/utils-reference/react-hooks/useCachedPromise.md | 12 ++++++------ docs/utils-reference/react-hooks/useExec.md | 10 +++++----- docs/utils-reference/react-hooks/useFetch.md | 12 ++++++------ docs/utils-reference/react-hooks/useForm.md | 2 +- docs/utils-reference/react-hooks/usePromise.md | 8 ++++---- docs/utils-reference/react-hooks/useSQL.md | 8 ++++---- src/useAI.ts | 1 - src/useCachedPromise.ts | 2 +- src/useExec.ts | 2 +- src/useFetch.ts | 2 +- src/useForm.tsx | 2 +- src/usePromise.ts | 2 +- src/useSQL.tsx | 2 +- 13 files changed, 32 insertions(+), 33 deletions(-) diff --git a/docs/utils-reference/react-hooks/useCachedPromise.md b/docs/utils-reference/react-hooks/useCachedPromise.md index 075203e..da24632 100644 --- a/docs/utils-reference/react-hooks/useCachedPromise.md +++ b/docs/utils-reference/react-hooks/useCachedPromise.md @@ -65,7 +65,7 @@ Returns an object with the [AsyncState](#asyncstate) corresponding to the execut import { Detail, ActionPanel, Action } from "@raycast/api"; import { useCachedPromise } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const abortable = useRef(); const { isLoading, data, revalidate } = useCachedPromise( async (url: string) => { @@ -90,7 +90,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Promise Argument dependent on List search text @@ -104,7 +104,7 @@ import { useState } from "react"; import { List, ActionPanel, Action } from "@raycast/api"; import { useCachedPromise } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const [searchText, setSearchText] = useState(""); const { isLoading, data } = useCachedPromise( async (url: string) => { @@ -126,7 +126,7 @@ const Demo = () => { ))} ); -}; +} ``` ## Mutation and Optimistic Updates @@ -141,7 +141,7 @@ When doing so, you can specify a `rollbackOnError` function to mutate back the d import { Detail, ActionPanel, Action, showToast, Toast } from "@raycast/api"; import { useCachedPromise } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const { isLoading, data, mutate } = useCachedPromise( async (url: string) => { const response = await fetch(url); @@ -188,7 +188,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Types diff --git a/docs/utils-reference/react-hooks/useExec.md b/docs/utils-reference/react-hooks/useExec.md index 21041a4..18f90d0 100644 --- a/docs/utils-reference/react-hooks/useExec.md +++ b/docs/utils-reference/react-hooks/useExec.md @@ -125,7 +125,7 @@ import { useMemo } from "react"; const brewPath = cpus()[0].model.includes("Apple") ? "/opt/homebrew/bin/brew" : "/usr/local/bin/brew"; -export default function () { +export default function Command() { const { isLoading, data } = useExec(brewPath, ["info", "--json=v2", "--installed"]); const results = useMemo<{ id: string; name: string }[]>(() => JSON.parse(data || "{}").formulae || [], [data]); @@ -150,12 +150,12 @@ import { useState } from "react"; import { Detail, ActionPanel, Action } from "@raycast/api"; import { useFetch } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const [searchText, setSearchText] = useState(""); const { isLoading, data } = useExec("brew", ["info", searchText]); return ; -}; +} ``` {% hint style="info" %} @@ -174,7 +174,7 @@ When doing so, you can specify a `rollbackOnError` function to mutate back the d import { Detail, ActionPanel, Action, showToast, Toast } from "@raycast/api"; import { useFetch } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const { isLoading, data, revalidate } = useExec("brew", ["info", "--json=v2", "--installed"]); const results = useMemo<{}[]>(() => JSON.parse(data || "[]"), [data]); @@ -219,7 +219,7 @@ const Demo = () => { ))} ); -}; +} ``` ## Types diff --git a/docs/utils-reference/react-hooks/useFetch.md b/docs/utils-reference/react-hooks/useFetch.md index feea42d..9101737 100644 --- a/docs/utils-reference/react-hooks/useFetch.md +++ b/docs/utils-reference/react-hooks/useFetch.md @@ -60,7 +60,7 @@ Returns an object with the [AsyncState](#asyncstate) corresponding to the execut import { Detail, ActionPanel, Action } from "@raycast/api"; import { useFetch } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const { isLoading, data, revalidate } = useFetch("https://api.example"); return ( @@ -74,7 +74,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Argument dependent on List search text @@ -88,7 +88,7 @@ import { useState } from "react"; import { List, ActionPanel, Action } from "@raycast/api"; import { useFetch } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const [searchText, setSearchText] = useState(""); const { isLoading, data } = useFetch(`https://api.example?q=${searchText}`, { // to make sure the screen isn't flickering when the searchText changes @@ -102,7 +102,7 @@ const Demo = () => { ))} ); -}; +} ``` ## Mutation and Optimistic Updates @@ -117,7 +117,7 @@ When doing so, you can specify a `rollbackOnError` function to mutate back the d import { Detail, ActionPanel, Action, showToast, Toast } from "@raycast/api"; import { useFetch } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const { isLoading, data, mutate } = useFetch("https://api.example"); const appendFoo = async () => { @@ -157,7 +157,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Types diff --git a/docs/utils-reference/react-hooks/useForm.md b/docs/utils-reference/react-hooks/useForm.md index 755e371..1581bf0 100644 --- a/docs/utils-reference/react-hooks/useForm.md +++ b/docs/utils-reference/react-hooks/useForm.md @@ -65,7 +65,7 @@ interface SignUpFormValues { hobbies: string[]; } -export default function Main() { +export default function Command() { const { handleSubmit, itemProps } = useForm({ onSubmit(values) { showToast({ diff --git a/docs/utils-reference/react-hooks/usePromise.md b/docs/utils-reference/react-hooks/usePromise.md index 56b6b56..493191c 100644 --- a/docs/utils-reference/react-hooks/usePromise.md +++ b/docs/utils-reference/react-hooks/usePromise.md @@ -54,7 +54,7 @@ Returns an object with the [AsyncState](#asyncstate) corresponding to the execut import { Detail, ActionPanel, Action } from "@raycast/api"; import { usePromise } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const abortable = useRef(); const { isLoading, data, revalidate } = usePromise( async (url: string) => { @@ -79,7 +79,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Mutation and Optimistic Updates @@ -94,7 +94,7 @@ When doing so, you can specify a `rollbackOnError` function to mutate back the d import { Detail, ActionPanel, Action, showToast, Toast } from "@raycast/api"; import { usePromise } from "@raycast/utils"; -const Demo = () => { +export default function Command() { const { isLoading, data, mutate } = usePromise( async (url: string) => { const response = await fetch(url); @@ -141,7 +141,7 @@ const Demo = () => { } /> ); -}; +} ``` ## Types diff --git a/docs/utils-reference/react-hooks/useSQL.md b/docs/utils-reference/react-hooks/useSQL.md index 4632dc1..47cfddd 100644 --- a/docs/utils-reference/react-hooks/useSQL.md +++ b/docs/utils-reference/react-hooks/useSQL.md @@ -61,7 +61,7 @@ type NoteItem = { title: string; }; -const Demo = () => { +export default function Command() { const { isLoading, data, permissionView } = useSQL(NOTES_DB, notesQuery); if (permissionView) { @@ -75,7 +75,7 @@ const Demo = () => { ))} ); -}; +} ``` ## Mutation and Optimistic Updates @@ -97,7 +97,7 @@ type NoteItem = { title: string; }; -const Demo = () => { +export default function Command() { const { isLoading, data, mutate, permissionView } = useFetch("https://api.example"); if (permissionView) { @@ -145,7 +145,7 @@ const Demo = () => { ))} ); -}; +} ``` ## Types diff --git a/src/useAI.ts b/src/useAI.ts index e33b2a6..9b443b9 100644 --- a/src/useAI.ts +++ b/src/useAI.ts @@ -4,7 +4,6 @@ import { PromiseOptions, usePromise } from "./usePromise"; import { FunctionReturningPromise } from "./types"; /** - * * Stream a prompt completion. * * @example diff --git a/src/useCachedPromise.ts b/src/useCachedPromise.ts index ac46d4c..7542a39 100644 --- a/src/useCachedPromise.ts +++ b/src/useCachedPromise.ts @@ -32,7 +32,7 @@ export type CachedPromiseOptions = Promis * ``` * import { useCachedPromise } from '@raycast/utils'; * - * const Demo = () => { + * export default function Command() { * const abortable = useRef(); * const { isLoading, data, revalidate } = useCachedPromise(async (url: string) => { * const response = await fetch(url, { signal: abortable.current?.signal }); diff --git a/src/useExec.ts b/src/useExec.ts index c58f946..f922784 100644 --- a/src/useExec.ts +++ b/src/useExec.ts @@ -99,7 +99,7 @@ type ExecCachedPromiseOptions = Omit< * ``` * import { useExec } from '@raycast/utils'; * - * const Demo = () => { + * export default function Command() { * const { isLoading, data, revalidate } = useExec("brew", ["info", "--json=v2", "--installed"]); * const results = useMemo<{}[]>(() => JSON.parse(data || "[]"), [data]); * diff --git a/src/useFetch.ts b/src/useFetch.ts index 26e2110..74ba6e1 100644 --- a/src/useFetch.ts +++ b/src/useFetch.ts @@ -51,7 +51,7 @@ async function defaultParsing(response: Response) { * ``` * import { useFetch } from '@raycast/utils'; * - * const Demo = () => { + * export default function Command() { * const { isLoading, data, revalidate } = useFetch('https://api.example'); * * return ( diff --git a/src/useForm.tsx b/src/useForm.tsx index 1eeb9a6..5016197 100644 --- a/src/useForm.tsx +++ b/src/useForm.tsx @@ -83,7 +83,7 @@ interface FormProps { * password: string; * } * - * export default function Main() { + * export default function Command() { * const { handleSubmit, itemProps } = useForm({ * onSubmit(values) { * showToast(Toast.Style.Success, "Yay!", `${values.nickname} account created`); diff --git a/src/usePromise.ts b/src/usePromise.ts index 79be984..02c812b 100644 --- a/src/usePromise.ts +++ b/src/usePromise.ts @@ -42,7 +42,7 @@ export type PromiseOptions = { * ``` * import { usePromise } from '@raycast/utils'; * - * const Demo = () => { + * export default function Command() { * const abortable = useRef(); * const { isLoading, data, revalidate } = usePromise(async (url: string) => { * const response = await fetch(url, { signal: abortable.current?.signal }); diff --git a/src/useSQL.tsx b/src/useSQL.tsx index aee35f8..404935a 100644 --- a/src/useSQL.tsx +++ b/src/useSQL.tsx @@ -38,7 +38,7 @@ import { handleErrorToastAction } from "./handle-error-toast-action"; * title: string; * }; * - * const Demo = () => { + * export default function Command() { * const { isLoading, data, permissionView } = useSQL(NOTES_DB, notesQuery); * * if (permissionView) {