Skip to content

Commit

Permalink
Only fetch saved elements once (#71310)
Browse files Browse the repository at this point in the history
Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
  • Loading branch information
Corey Robertson and elasticmachine authored Jul 14, 2020
1 parent 763390f commit 1ceaea1
Showing 1 changed file with 14 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,14 @@
* you may not use this file except in compliance with the Elastic License.
*/

import React, { Fragment, ChangeEvent, FunctionComponent, useState, useEffect } from 'react';
import React, {
Fragment,
ChangeEvent,
FunctionComponent,
useState,
useEffect,
useRef,
} from 'react';
import PropTypes from 'prop-types';
import {
EuiModal,
Expand Down Expand Up @@ -72,12 +79,16 @@ export const SavedElementsModal: FunctionComponent<Props> = ({
removeCustomElement,
updateCustomElement,
}) => {
const hasLoadedElements = useRef<boolean>(false);
const [elementToDelete, setElementToDelete] = useState<CustomElement | null>(null);
const [elementToEdit, setElementToEdit] = useState<CustomElement | null>(null);

useEffect(() => {
findCustomElements();
});
if (!hasLoadedElements.current) {
hasLoadedElements.current = true;
findCustomElements();
}
}, [findCustomElements, hasLoadedElements]);

const showEditModal = (element: CustomElement) => setElementToEdit(element);
const hideEditModal = () => setElementToEdit(null);
Expand Down

0 comments on commit 1ceaea1

Please sign in to comment.