raycast-hooks
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "raycast-hooks", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Hooks for Raycast extensions", | ||
@@ -26,3 +26,3 @@ "main": "src/index.js", | ||
"devDependencies": { | ||
"@raycast/api": "^1.27.1", | ||
"@raycast/api": "^1.31.0", | ||
"@types/react": "^17.0.38", | ||
@@ -29,0 +29,0 @@ "@typescript-eslint/eslint-plugin": "^5.10.1", |
@@ -126,2 +126,25 @@ # raycast-hooks | ||
}/> | ||
``` | ||
``` | ||
## useClipboard | ||
Get the clipboard contents. As the clipboard will return undefined if it's not a string, you might want to show a different message based on if it's returned and empty or not yet returned. This simple hook exposes the clipboard contents and a ready flag, and helps avoid a flash of error if your content requires a clipboard item. | ||
```tsx | ||
import {useClipboard} from "raycast-hooks"; | ||
const [ready, clipboard] = useClipboard(defaults); | ||
if (!ready || clipboard === undefined || clipboard.length === 0) { | ||
return <List isLoading={!ready}> | ||
<List.EmptyView | ||
icon={'your-icon.png'} | ||
title="Please copy the thing to your clipboard" | ||
/> | ||
</List>; | ||
} | ||
// rest of extension goes here | ||
``` | ||
Using this format you will show the list as loading screen rather than the `EmptyView` whilst your extension is reading from the clipboard. |
@@ -26,5 +26,7 @@ import { useCallback, useEffect, useState } from "react"; | ||
(...rest: (FavList | undefined)[]) => void, | ||
(item: string) => Promise<void>, | ||
(item: string) => Promise<void>, | ||
() => Promise<void> | ||
{ | ||
add: (item: string) => Promise<void>, | ||
remove: (item: string) => Promise<void>, | ||
reset: () => Promise<void>, | ||
}, | ||
] { | ||
@@ -40,3 +42,3 @@ const [allLists, setAll] = useState(lists); | ||
const addFav = useCallback( | ||
const add = useCallback( | ||
async (item: string) => { | ||
@@ -52,3 +54,3 @@ const favs = await getFavs(key); | ||
const remFav = useCallback( | ||
const remove = useCallback( | ||
async (item: string) => { | ||
@@ -61,3 +63,3 @@ const favs = (await getFavs(key)).filter((fav) => fav !== item); | ||
const resetFavs = useCallback(async () => { | ||
const reset = useCallback(async () => { | ||
await updateFavs(key, [] as FavList); | ||
@@ -67,3 +69,3 @@ setFavs([] as FavList); | ||
return [favs || [], stripFavs(allLists, favs), setLists, addFav, remFav, resetFavs]; | ||
return [favs || [], stripFavs(allLists, favs), setLists, { add, remove, reset}]; | ||
} |
@@ -21,3 +21,3 @@ import { useCallback, useEffect, useState } from "react"; | ||
defaults: PrefList | ||
): [PrefList, (pref: string, value: boolean | string) => Promise<void>, () => void] { | ||
): [PrefList, {update: (pref: string, value: boolean | string) => Promise<void>, reset: () => void}] { | ||
const [prefs, setPrefs] = useState<PrefList>(defaults); | ||
@@ -29,3 +29,3 @@ | ||
const updatePref = useCallback(async (pref: string, value: boolean | string) => { | ||
const update = useCallback(async (pref: string, value: boolean | string) => { | ||
const prefs = await getPrefs(); | ||
@@ -37,7 +37,7 @@ prefs[pref] = value; | ||
const resetPrefs = useCallback(() => { | ||
const reset = useCallback(() => { | ||
updatePrefs(defaults).then(() => setPrefs(defaults)); | ||
}, [defaults]); | ||
return [prefs, updatePref, resetPrefs]; | ||
return [prefs, {update, reset}]; | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
14589
17
189
150