• Custom React hook to manage quest types.

    Parameters

    • params: {
          [key: string]: any;
      }

      Parameters to pass to the API request.

      • [key: string]: any

    Returns UseQuestTypesReturn

    The returning object contains:

    • questTypes: An array of quest type objects representing the fetched quest types.
    • fetched: Boolean indicating whether the quest types has been successfully fetched.
    • refresh: FetchQuestTypeMethod - Function to refetch the quest types.
    • Caching: getQuestTypes responses are cached for 5 minutes (300,000 ms) using withCache, reducing redundant API calls.
    • Effect Trigger: The useEffect hook triggers fetchQuestTypes whenever params change, ensuring the list is always up to date.
    • Error Handling: Errors during data fetching are logged to the console and re-thrown with additional context for easier debugging.
    • Fetch Logic:
      • fetchQuestTypes: Fetches quest types based on the provided params. A quiet flag can suppress loading state updates.

    Example

    import { useQuestTypes } from 'react-playmakers';

    // Use the hook within a functional component
    const QuestTypes = () => {
    const { questTypes, fetched, refresh } = useQuestTypes({ region: 'north' });

    useEffect(() => {
    if (fetched) {
    console.log("Quest types fetched:", questTypes);
    }
    }, [fetched]);

    return (
    <div>
    {fetched ? (
    <ul>
    {questTypes.map((quest) => (
    <li key={quest.id}>{quest.name}</li>
    ))}
    </ul>
    ) : (
    <p>Loading quest types...</p>
    )}
    <button onClick={() => refresh(true)}>Refresh</button>
    </div>
    );
    };

Generated using TypeDoc