Skip to content

Commit ce8a92e

Browse files
authored
[Observability Homepage] Fix console error because of side effect (#75258)
1 parent e077a28 commit ce8a92e

1 file changed

Lines changed: 9 additions & 7 deletions

File tree

  • x-pack/plugins/observability/public/pages/home

x-pack/plugins/observability/public/pages/home/index.tsx

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* or more contributor license agreements. Licensed under the Elastic License;
44
* you may not use this file except in compliance with the Elastic License.
55
*/
6-
import React from 'react';
6+
import React, { useEffect } from 'react';
77
import { useHistory } from 'react-router-dom';
88
import { fetchHasData } from '../../data_handler';
99
import { useFetcher } from '../../hooks/use_fetcher';
@@ -15,12 +15,14 @@ export function HomePage() {
1515
const values = Object.values(data);
1616
const hasSomeData = values.length ? values.some((hasData) => hasData) : null;
1717

18-
if (hasSomeData === true) {
19-
history.push({ pathname: '/overview' });
20-
}
21-
if (hasSomeData === false) {
22-
history.push({ pathname: '/landing' });
23-
}
18+
useEffect(() => {
19+
if (hasSomeData === true) {
20+
history.push({ pathname: '/overview' });
21+
}
22+
if (hasSomeData === false) {
23+
history.push({ pathname: '/landing' });
24+
}
25+
}, [hasSomeData, history]);
2426

2527
return <></>;
2628
}

0 commit comments

Comments
 (0)