import {useEffect, useState} from "react"; import {subscribeToLight, unsubscribeFromLight} from "../Helpers/lights"; export default function useLights({groupId = -1, id = -1} = {}) { const [light, setLight] = useState(null); function onChange(light) { setLight(light); } useEffect(() => { const cbId = subscribeToLight(id, onChange); return () => { unsubscribeFromLight(cbId); }; }, []); if (groupId >= 0 && light !== null) { return light.filter(l => l.groupId === groupId); } return light; }