From 3c7a3e54b9f34b84acfbb3d15f7500185fe78067 Mon Sep 17 00:00:00 2001 From: Sean Sube Date: Sat, 11 Feb 2023 17:25:16 -0600 Subject: [PATCH] fix(gui): correct react update during render --- gui/src/components/input/QueryList.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gui/src/components/input/QueryList.tsx b/gui/src/components/input/QueryList.tsx index f4f75035..11e05c04 100644 --- a/gui/src/components/input/QueryList.tsx +++ b/gui/src/components/input/QueryList.tsx @@ -1,6 +1,7 @@ import { doesExist, mustDefault, mustExist } from '@apextoaster/js-utils'; import { Alert, FormControl, InputLabel, MenuItem, Select, Typography } from '@mui/material'; import * as React from 'react'; +import { useEffect } from 'react'; import { UseQueryResult } from 'react-query'; export interface QueryListComplete { @@ -48,6 +49,15 @@ export function QueryList(props: QueryListProps) { } } + useEffect(() => { + if (result.status === 'success' && doesExist(result.data) && doesExist(props.onChange)) { + const data = filterQuery(query); + if (data.includes(value) === false) { + props.onChange(data[0]); + } + } + }, [result.status]); + if (result.status === 'error') { if (result.error instanceof Error) { return Error: {result.error.message};