1
Fork 0
mirror of https://github.com/Steffo99/todocolors.git synced 2024-11-25 17:54:18 +00:00

Add isStarred callback to StarredProvider

This commit is contained in:
Steffo 2023-08-09 04:28:18 +02:00
parent e27ace8d13
commit 506a27e989
Signed by: steffo
GPG key ID: 2A24051445686895
2 changed files with 6 additions and 1 deletions

View file

@ -6,4 +6,5 @@ export interface StarredContextData {
setStarred: Dispatch<SetStateAction<string[] | undefined>>
addStarred: (key: string) => void,
removeStarred: (key: string) => void,
isStarred: (key: string) => boolean,
}

View file

@ -32,8 +32,12 @@ export function StarredProvider({children}: {children: ReactNode}) {
})
}, [])
const isStarred = useCallback((value: string) => {
return starred.indexOf(value) >= 0
}, [starred])
return (
<StarredContext.Provider value={{starred, setStarred, addStarred, removeStarred}}>
<StarredContext.Provider value={{starred, setStarred, addStarred, removeStarred, isStarred}}>
{children}
</StarredContext.Provider>
)