Skip to content

Commit

Permalink
use memo to avoid needless rerendering
Browse files Browse the repository at this point in the history
  • Loading branch information
gmmorris committed Nov 19, 2020
1 parent 1ec6e70 commit 781975e
Showing 1 changed file with 15 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* or more contributor license agreements. Licensed under the Elastic License;
* you may not use this file except in compliance with the Elastic License.
*/
import React, { useCallback, useReducer, useState, useEffect } from 'react';
import React, { useCallback, useReducer, useMemo, useState, useEffect } from 'react';
import { FormattedMessage } from '@kbn/i18n/react';
import { EuiTitle, EuiFlyoutHeader, EuiFlyout, EuiFlyoutBody, EuiPortal } from '@elastic/eui';
import { i18n } from '@kbn/i18n';
Expand Down Expand Up @@ -35,17 +35,20 @@ export const AlertAdd = ({
alertTypeId,
initialValues,
}: AlertAddProps) => {
const initialAlert: InitialAlert = {
params: {},
consumer,
alertTypeId,
schedule: {
interval: '1m',
},
actions: [],
tags: [],
...(initialValues ? initialValues : {}),
};
const initialAlert: InitialAlert = useMemo(
() => ({
params: {},
consumer,
alertTypeId,
schedule: {
interval: '1m',
},
actions: [],
tags: [],
...(initialValues ? initialValues : {}),
}),
[alertTypeId, consumer, initialValues]
);

const [{ alert }, dispatch] = useReducer(alertReducer as InitialAlertReducer, {
alert: initialAlert,
Expand Down

0 comments on commit 781975e

Please sign in to comment.