[Canvas] Fixes Advanced settings in Datasource recreate on any change. (#111840)

* added useEffectOnce.

Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
Yaroslav Kuznietsov 2021-09-14 16:24:01 +03:00 committed by GitHub
parent dd3053d23e
commit ec313f6373
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 5 deletions

View file

@ -12,7 +12,9 @@ import { DatasourceComponent } from './datasource_component';
export const Datasource = (props) => {
const { datasource, stateDatasource } = props;
if (!datasource || !stateDatasource) return <NoDatasource {...props} />;
if (!datasource || !stateDatasource) {
return <NoDatasource {...props} />;
}
return <DatasourceComponent {...props} />;
};

View file

@ -6,6 +6,7 @@
*/
import React, { useEffect, useRef, useCallback } from 'react';
import useEffectOnce from 'react-use/lib/useEffectOnce';
import { Ast } from '@kbn/interpreter/common';
import { RenderToDom } from '../components/render_to_dom';
import { BaseForm, BaseFormProps } from './base_form';
@ -62,10 +63,11 @@ const DatasourceWrapper: React.FunctionComponent<DatasourceWrapperProps> = (prop
useEffect(() => {
callRenderFn();
return () => {
handlers.destroy();
};
}, [callRenderFn, handlers, props]);
}, [callRenderFn, props]);
useEffectOnce(() => () => {
handlers.destroy();
});
return (
<RenderToDom