Function useQuestTypeCategories

  • Custom React hook to manage quest type.

    Parameters

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

      Parameters to pass to the API request.

      • [key: string]: any

    Returns UseQuestTypeCategoriesReturn

    The returning object contains:

    • categories: An array of string objects representing the fetched quest type categories.
    • fetched: Boolean indicating whether the quest type has been successfully fetched.
    • refresh: FetchQuestTypeCategoriesMethod - Function to refetch the quest type categories.

    Implementation Details

    • Caching: getQuestTypeCategories responses are cached for 5 minutes (300,000 ms) using withCache. Cache is cleared when refresh is triggered.
    • Effect Trigger: The useEffect hook triggers fetchQuestTypeCategories whenever params change, ensuring the category list is up to date.
    • Error Handling: Errors during fetching are logged to the console and re-thrown with additional context.
    • Fetch Logic:
      • fetchQuestTypeCategories: Fetches categories based on params, with options for a quiet mode and cache bypass (refresh).

    Example

    import { useQuestTypeCategories } from 'react-playmakers';

    const CategoriesComponent = () => {
    const { categories, fetched, refresh } = useQuestTypeCategories({ type: 'adventure' });

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

    return (
    <div>
    {fetched ? (
    <ul>
    {categories.map((category) => (
    <li key={category}>{category}</li>
    ))}
    </ul>
    ) : (
    <p>Loading quest type categories...</p>
    )}
    <button onClick={() => refresh(true)}>Refresh</button>
    </div>
    );
    };

Generated using TypeDoc