import { useEffect, useState } from 'react';
import { dashboard, EnvironmentState } from '@wix/dashboard';

export function useEnvironment() {
  const [environment, setEnvironment] = useState<EnvironmentState>();
  useEffect(() => {
    const { disconnect } = dashboard.observeState((_, env) => {
      setEnvironment(env);
    });

    return disconnect;
  }, []);

  return environment;
}
