Favorites Context Provider (contexts/favorites-context.tsx)

llms-txt-hub · ui, UI / Frontend, react, context, localstorage, auth, state

React context that manages user favorites with localStorage persistence and optional server sync, exposing helpers to add, remove, toggle, and check favorites.

// Source: https://github.com/mperkins0155/llms-txt-hub | License: MIT | Copyright 2025 David Dias
// Provided via justclaw.it.com; keep this notice with the code.
'use client'

import { useAuth } from '@thedaviddias/auth'
import { logger } from '@thedaviddias/logging'
import { createContext, type ReactNode, useCallback, useContext, useEffect, useState } from 'react'

export interface FavoritesContextValue {
  favorites: string[]
  isFavorite: (slug: string) => boolean
  addFavorite: (slug: string) => void
  removeFavorite: (slug: string) => void
  toggleFavorite: (slug: string) => void
  isLoading: boolean
}

const FavoritesContext = createContext<FavoritesContextValue | null>(null)

const STORAGE_KEY = 'llms-txt-hub-favorites'

interface FavoritesProviderProps {
  children: ReactNode
}



... (truncated -- full source via MCP)

See the full source, get the GitHub permalink, and search 40K more like it.

Get a free API key