• Custom React hook for fetching and managing referral data.

    Parameters

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

    Returns {
        assignReferralCode: AssignReferralCodeMethod;
        fetched: boolean;
        getReferralCode: ReferralCodeMethod;
        referees: Referee[];
        referrer: null | Referrer;
        refresh: ((quiet?) => Promise<Referral>);
    }

    The returning object contains:

    • fetched: A boolean flag indicating whether the referral data has been fetched.
    • referral: The fetched referral data, or null if not yet fetched.
    • refresh: Function to refresh the referral data.
    • assignReferralCode: AssignReferralCodeMethod
    • fetched: boolean
    • getReferralCode: ReferralCodeMethod
    • referees: Referee[]
    • referrer: null | Referrer
    • refresh: ((quiet?) => Promise<Referral>)
        • (quiet?): Promise<Referral>
        • Parameters

          • quiet: boolean = false

          Returns Promise<Referral>

    Example

    import {useReferral} from "react-playmakers";

    const ReferralComponent: React.FC = () => {
    const {referral, fetched, refresh, getReferralCode, assignReferralCode} = useReferral();

    useEffect(() => {
    if (fetched) {
    console.log(referral);
    }
    }, [fetched, referral]);

    const handleRefresh = () => {
    refresh();
    };

    return (
    <div>
    <h1>Referral:</h1>
    {fetched && referral?.referrer ? (
    <div>
    <p>Referrer ID: {referrer.id}</p>
    <p>Referrer Username: {referrer.username}</p>
    <p>Referrer Avatar: {referrer.avatar}</p>
    <p>Referrer Referral Code: {referrer.referralCode}</p>
    </div>
    ) : (
    <p>No referrer found</p>
    )}

    {fetched && referral?.referees.map((referee) => (
    <div key={referee.id}>
    <p>Referee ID: {referee.id}</p>
    <p>Referee Username: {referee.username}</p>
    <p>Referee Avatar: {referee.avatar}</p>
    </div>
    ))}
    <button onClick={handleRefresh}>Refresh</button>
    <button onClick={getReferralCode}>Get Referral Code</button>
    <button onClick={() => assignReferralCode("code")}>Assign Referral Code</button>
    <p>Referral Code: {referrer?.referralCode}</p>
    <p>Referral Code: {referees[0]?.referralCode}</p>
    </div>
    );
    };

Generated using TypeDoc