• Custom React hook to manage quest type.

    Parameters

    • Optional id: string

    Returns UseQuestTypeReturn

    The returning object contains:

    • questType: The current quest type object.
    • fetched: Boolean indicating whether the quest type has been successfully fetched.
    • refresh: FetchQuestTypeMethod - Function to refetch the quest type.
    • Caching: getQuestType responses are cached for 5 minutes (300,000 ms) using withCache to reduce redundant API calls. Cache is cleared when refresh is triggered.
    • Effect Trigger: The useEffect hook triggers fetchQuestType whenever the id changes, ensuring the correct quest type is fetched.
    • Error Handling: Errors during the fetch process are logged to the console and re-thrown with additional context.
    • State Management:
      • questType: Holds the fetched quest type data or null if not yet fetched.
      • fetched: Tracks whether the fetch process has completed.
    • Fetch Logic:
      • fetchQuestType: Fetches the quest type using the provided id. Optionally accepts a quiet flag to suppress loading state updates and a refresh flag to bypass the cache.

    Example

    import { useQuestType } from 'react-playmakers';

    const QuestDetails = () => {
    const { fetched, questType, refresh } = useQuestType('qXXXXXXX');

    if (!fetched) {
    return <div>Loading...</div>;
    }

    if (!questType) {
    return <div>No quest type found.</div>;
    }

    return (
    <div>
    <h1>{questType.name}</h1>
    <p>{questType.description}</p>
    <button onClick={() => refresh(true)}>Refresh</button>
    </div>
    );
    };

    export default QuestDetails;

Generated using TypeDoc