elastic: eliminate react warning (#52934)

This commit is contained in:
Gábor Farkas
2022-07-29 14:24:33 +02:00
committed by GitHub
parent e88e3482e0
commit ba76f9b580

View File

@@ -1,4 +1,4 @@
import React, { Context, createContext, PropsWithChildren, useCallback, useContext } from 'react';
import React, { Context, createContext, PropsWithChildren, useCallback, useContext, useEffect } from 'react';
import { TimeRange } from '@grafana/data';
@@ -52,11 +52,18 @@ export const ElasticsearchProvider = ({
reducer
);
const isUninitialized = !query.metrics || !query.bucketAggs || query.query === undefined;
// This initializes the query by dispatching an init action to each reducer.
// useStatelessReducer will then call `onChange` with the newly generated query
if (!query.metrics || !query.bucketAggs || query.query === undefined) {
dispatch(initQuery());
useEffect(() => {
if (isUninitialized) {
dispatch(initQuery());
}
});
if (isUninitialized) {
return null;
}