The main server, and probably only repository in this org.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

24 lines
540 B

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;
}