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.

23 lines
540 B

5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
5 years ago
  1. import {useEffect, useState} from "react";
  2. import {subscribeToLight, unsubscribeFromLight} from "../Helpers/lights";
  3. export default function useLights({groupId = -1, id = -1} = {}) {
  4. const [light, setLight] = useState(null);
  5. function onChange(light) {
  6. setLight(light);
  7. }
  8. useEffect(() => {
  9. const cbId = subscribeToLight(id, onChange);
  10. return () => {
  11. unsubscribeFromLight(cbId);
  12. };
  13. }, []);
  14. if (groupId >= 0 && light !== null) {
  15. return light.filter(l => l.groupId === groupId);
  16. }
  17. return light;
  18. }