@hakit/core
Version:
A collection of React hooks and helpers for Home Assistant to easily communicate with the Home Assistant WebSocket API.
3 lines (2 loc) • 805 B
JavaScript
;Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const g=require("../useStore/index.js"),t=require("react");function S(a){const i=t.useRef(!1),r=g.useStore(u=>u.connection),[s,n]=t.useState({loading:!0,error:null,users:[]}),o=t.useCallback(async({includeSystemGenerated:u=!1,includeInactiveUsers:d=!1}={})=>{if(!r)return s;i.current=!0,n(e=>({...e,error:null,loading:!0}));try{const l={loading:!1,error:null,users:(await r.sendMessagePromise({type:"config/auth/list"})).filter(f=>!(!u&&f.system_generated||!d&&!f.is_active))};return n(l),l}catch(e){const c={loading:!1,error:e instanceof Error?e.message:"Unknown error",users:[]};return n(c),c}},[r,s]);return t.useEffect(()=>{i.current||o(a)},[r,o,a]),{...s,refetch:o}}exports.useUsers=S;
//# sourceMappingURL=index.js.map