@splitsoftware/splitio-react
Version:
A React library to easily integrate and use Split JS SDK
21 lines (20 loc) • 1.27 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.useTrack = void 0;
var useSplitClient_1 = require("./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://developer.harness.io/docs/feature-management-experimentation/sdks-and-infrastructure/client-side-sdks/javascript-sdk/#track}
*/
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 = (0, useSplitClient_1.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;
}
exports.useTrack = useTrack;
;