diff --git a/x-pack/plugins/security_solution/public/common/components/query_bar/index.tsx b/x-pack/plugins/security_solution/public/common/components/query_bar/index.tsx index aea4874f9a2ef..9356956c23d56 100644 --- a/x-pack/plugins/security_solution/public/common/components/query_bar/index.tsx +++ b/x-pack/plugins/security_solution/public/common/components/query_bar/index.tsx @@ -110,21 +110,22 @@ export const QueryBar = memo( ); useEffect(() => { + let dv: DataView; if (isDataView(indexPattern)) { setDataView(indexPattern); } else { const createDataView = async () => { - const dv = await data.dataViews.create({ title: indexPattern.title }); + dv = await data.dataViews.create({ title: indexPattern.title }); setDataView(dv); }; createDataView(); } return () => { - if (dataView?.id) { - data.dataViews.clearInstanceCache(dataView?.id); + if (dv?.id) { + data.dataViews.clearInstanceCache(dv?.id); } }; - }, [data.dataViews, dataView?.id, indexPattern]); + }, [data.dataViews, indexPattern]); const timeHistory = useMemo(() => new TimeHistory(new Storage(localStorage)), []); const arrDataView = useMemo(() => (dataView != null ? [dataView] : []), [dataView]);