UNPKG

usefloc

Version:

React Hook to use FLoC API <pre>yarn add usefloc</pre>

20 lines (17 loc) 447 B
import { useState, useEffect } from 'react'; const useFLoC = () => { const [{ id, version }, setState] = useState<{ id: string | null; version: string | null; }>({ id: null, version: null }); useEffect(() => { const getCohort = async () => { // @ts-ignore const cohort = await document.interestCohort(); setState(cohort); }; getCohort(); }, []); return { id, version }; }; export default useFLoC;