Function useTags

  • Custom React hook to fetch and manage tags for a specific project.

    Parameters

    • projectId: any

      The ID of the project for which tags are fetched. Can be undefined.

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

      The object containing additional query parameters to refine the tag fetch request.

      • [key: string]: any

    Returns UseTagsReturn

    The object containing:

    • refresh: FetchTagsMethod - Function to refresh the tags by re-fetching them from the backend.
    • fetched: A boolean flag indicating whether the user data has been fetched.
    • tags: The current list of tags fetched for the given projectId and params.

    Implementation Details

    • Caching: The hook uses withCache to cache the tags for 5 minutes (300,000 ms).
    • Error Handling: Errors during the fetch are logged to the console and re-thrown with a cause.

    Throws

    Error - If the tag fetching process fails, an error with the underlying cause is thrown.

    Example

    import { useTags } from 'react-playmakers';

    function ProjectTags(){
    const { tags, fetched, refresh } = useTags('pXXXXXXXX', { page: 1 });

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

    return (
    <div>
    <h2>Project Tags</h2>
    {tags.length === 0 ? (
    <p>No tags found for this project.</p>
    ) : (
    <ul>
    {tags.map((tag, index) => (
    <li key={index}>{tag}</li>
    ))}
    </ul>
    )}
    <button onClick={() => refresh()}>Refresh Tags</button>
    </div>
    );
    }

Generated using TypeDoc