Skip to content

Commit

Permalink
remove ref
Browse files Browse the repository at this point in the history
  • Loading branch information
angorayc committed Oct 2, 2023
1 parent e9cc346 commit 0083b75
Showing 1 changed file with 12 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,11 @@ const DashboardRendererComponent = ({
}),
[embeddable, filters, query, timeRange, viewMode]
);
const [dashboardContainerRenderer, setDashboardContainerRenderer] = useState<
React.ReactElement | undefined
>(undefined);

const refetchByForceRefresh = useCallback(() => {
dashboardContainer?.forceRefresh();
}, [dashboardContainer]);

const wrapperRef = useRef(null);

useEffect(() => {
dispatch(
inputsActions.setQuery({
Expand Down Expand Up @@ -112,23 +107,25 @@ const DashboardRendererComponent = ({
/** Dashboard renderer is stored in the state as it's a temporary solution for
* https://github.com/elastic/kibana/issues/167751
**/
const [dashboardContainerRenderer, setDashboardContainerRenderer] = useState<
React.ReactElement | undefined
>(undefined);

useEffect(() => {
if (wrapperRef) {
setDashboardContainerRenderer(
<DashboardContainerRenderer
ref={onDashboardContainerLoaded}
savedObjectId={savedObjectId}
getCreationOptions={getCreationOptions}
/>
);
}
setDashboardContainerRenderer(
<DashboardContainerRenderer
ref={onDashboardContainerLoaded}
savedObjectId={savedObjectId}
getCreationOptions={getCreationOptions}
/>
);

return () => {
setDashboardContainerRenderer(undefined);
};
}, [getCreationOptions, onDashboardContainerLoaded, refetchByForceRefresh, savedObjectId]);

return canReadDashboard ? <div ref={wrapperRef}>{dashboardContainerRenderer}</div> : null;
return canReadDashboard ? <>{dashboardContainerRenderer}</> : null;
};
DashboardRendererComponent.displayName = 'DashboardRendererComponent';
export const DashboardRenderer = React.memo(DashboardRendererComponent);

0 comments on commit 0083b75

Please sign in to comment.