github.com/martinohmann/rfoutlet@v1.2.1-0.20220707195255-8a66aa411105/web/src/hooks.js (about) 1 import { useContext } from 'react'; 2 import Context from './Context'; 3 import { useParams } from 'react-router'; 4 5 export function useOutlets() { 6 return useContext(Context).outlets; 7 } 8 9 export function useOutlet(outletId) { 10 const outlets = useOutlets(); 11 12 return outlets.find(outlet => outlet.id === outletId); 13 } 14 15 export function useCurrentOutlet() { 16 const { outletId } = useParams(); 17 18 return useOutlet(outletId); 19 } 20 21 export function useIntervals() { 22 return useContext(Context).intervals; 23 } 24 25 export function useInterval(intervalId) { 26 const intervals = useIntervals(); 27 28 return intervals.find(interval => interval.id === intervalId); 29 } 30 31 export function useCurrentInterval() { 32 const { intervalId } = useParams(); 33 34 return useInterval(intervalId); 35 } 36 37