UNPKG

@splitsoftware/splitio-react

Version:

A React library to easily integrate and use Split JS SDK

17 lines (16 loc) 1.06 kB
import { useSplitClient } from './useSplitClient'; // no-op function that returns false var noOpFalse = function () { return false; }; /** * `useTrack` is a hook that retrieves the track method from a Split client. * * @returns The track method of the Split client for the provided user key. If the client is not available, the result is a no-op function that returns false. * * @see {@link https://help.split.io/hc/en-us/articles/360020448791-JavaScript-SDK#track} */ export function useTrack(splitKey) { // All update options are false to avoid re-renders. The track method doesn't need the client to be operational. var client = useSplitClient({ splitKey: splitKey, updateOnSdkReady: false, updateOnSdkReadyFromCache: false, updateOnSdkTimedout: false, updateOnSdkUpdate: false }).client; // Retrieve the client `track` rather than a bound version of it, as there is no need to bind the function, and can be used as a reactive dependency that only changes if the underlying client changes. return client ? client.track : noOpFalse; }