Skip to content

Commit

Permalink
Docs: Use export for examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mathieudutour committed Jul 18, 2023
1 parent 3097841 commit 1f5b738
Show file tree
Hide file tree
Showing 13 changed files with 32 additions and 33 deletions.
12 changes: 6 additions & 6 deletions docs/utils-reference/react-hooks/useCachedPromise.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbortController>();
const { isLoading, data, revalidate } = useCachedPromise(
async (url: string) => {
Expand All @@ -90,7 +90,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Promise Argument dependent on List search text
Expand All @@ -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) => {
Expand All @@ -126,7 +126,7 @@ const Demo = () => {
))}
</List>
);
};
}
```

## Mutation and Optimistic Updates
Expand All @@ -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);
Expand Down Expand Up @@ -188,7 +188,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Types
Expand Down
10 changes: 5 additions & 5 deletions docs/utils-reference/react-hooks/useExec.md
Original file line number Diff line number Diff line change
Expand Up @@ -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]);

Expand All @@ -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 <Detail isLoading={isLoading} markdown={data} />;
};
}
```

{% hint style="info" %}
Expand All @@ -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]);

Expand Down Expand Up @@ -219,7 +219,7 @@ const Demo = () => {
))}
</List>
);
};
}
```

## Types
Expand Down
12 changes: 6 additions & 6 deletions docs/utils-reference/react-hooks/useFetch.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand All @@ -74,7 +74,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Argument dependent on List search text
Expand All @@ -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
Expand All @@ -102,7 +102,7 @@ const Demo = () => {
))}
</List>
);
};
}
```

## Mutation and Optimistic Updates
Expand All @@ -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 () => {
Expand Down Expand Up @@ -157,7 +157,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Types
Expand Down
2 changes: 1 addition & 1 deletion docs/utils-reference/react-hooks/useForm.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ interface SignUpFormValues {
hobbies: string[];
}

export default function Main() {
export default function Command() {
const { handleSubmit, itemProps } = useForm<SignUpFormValues>({
onSubmit(values) {
showToast({
Expand Down
8 changes: 4 additions & 4 deletions docs/utils-reference/react-hooks/usePromise.md
Original file line number Diff line number Diff line change
Expand Up @@ -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<AbortController>();
const { isLoading, data, revalidate } = usePromise(
async (url: string) => {
Expand All @@ -79,7 +79,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Mutation and Optimistic Updates
Expand All @@ -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);
Expand Down Expand Up @@ -141,7 +141,7 @@ const Demo = () => {
}
/>
);
};
}
```

## Types
Expand Down
8 changes: 4 additions & 4 deletions docs/utils-reference/react-hooks/useSQL.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ type NoteItem = {
title: string;
};

const Demo = () => {
export default function Command() {
const { isLoading, data, permissionView } = useSQL<NoteItem>(NOTES_DB, notesQuery);

if (permissionView) {
Expand All @@ -75,7 +75,7 @@ const Demo = () => {
))}
</List>
);
};
}
```

## Mutation and Optimistic Updates
Expand All @@ -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) {
Expand Down Expand Up @@ -145,7 +145,7 @@ const Demo = () => {
))}
</List>
);
};
}
```

## Types
Expand Down
1 change: 0 additions & 1 deletion src/useAI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { PromiseOptions, usePromise } from "./usePromise";
import { FunctionReturningPromise } from "./types";

/**
*
* Stream a prompt completion.
*
* @example
Expand Down
2 changes: 1 addition & 1 deletion src/useCachedPromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export type CachedPromiseOptions<T extends FunctionReturningPromise, U> = Promis
* ```
* import { useCachedPromise } from '@raycast/utils';
*
* const Demo = () => {
* export default function Command() {
* const abortable = useRef<AbortController>();
* const { isLoading, data, revalidate } = useCachedPromise(async (url: string) => {
* const response = await fetch(url, { signal: abortable.current?.signal });
Expand Down
2 changes: 1 addition & 1 deletion src/useExec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type ExecCachedPromiseOptions<T, U> = 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]);
*
Expand Down
2 changes: 1 addition & 1 deletion src/useFetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down
2 changes: 1 addition & 1 deletion src/useForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ interface FormProps<T extends Form.Values> {
* password: string;
* }
*
* export default function Main() {
* export default function Command() {
* const { handleSubmit, itemProps } = useForm<SignUpFormValues>({
* onSubmit(values) {
* showToast(Toast.Style.Success, "Yay!", `${values.nickname} account created`);
Expand Down
2 changes: 1 addition & 1 deletion src/usePromise.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ export type PromiseOptions<T extends FunctionReturningPromise> = {
* ```
* import { usePromise } from '@raycast/utils';
*
* const Demo = () => {
* export default function Command() {
* const abortable = useRef<AbortController>();
* const { isLoading, data, revalidate } = usePromise(async (url: string) => {
* const response = await fetch(url, { signal: abortable.current?.signal });
Expand Down
2 changes: 1 addition & 1 deletion src/useSQL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ import { handleErrorToastAction } from "./handle-error-toast-action";
* title: string;
* };
*
* const Demo = () => {
* export default function Command() {
* const { isLoading, data, permissionView } = useSQL<NoteItem>(NOTES_DB, notesQuery);
*
* if (permissionView) {
Expand Down

0 comments on commit 1f5b738

Please sign in to comment.