1
0
Fork 0

fix(gui): correct react update during render

This commit is contained in:
Sean Sube 2023-02-11 17:25:16 -06:00
parent 44c9524cd2
commit 3c7a3e54b9
Signed by: ssube
GPG Key ID: 3EED7B957D362AF1
1 changed files with 10 additions and 0 deletions

View File

@ -1,6 +1,7 @@
import { doesExist, mustDefault, mustExist } from '@apextoaster/js-utils'; import { doesExist, mustDefault, mustExist } from '@apextoaster/js-utils';
import { Alert, FormControl, InputLabel, MenuItem, Select, Typography } from '@mui/material'; import { Alert, FormControl, InputLabel, MenuItem, Select, Typography } from '@mui/material';
import * as React from 'react'; import * as React from 'react';
import { useEffect } from 'react';
import { UseQueryResult } from 'react-query'; import { UseQueryResult } from 'react-query';
export interface QueryListComplete { export interface QueryListComplete {
@ -48,6 +49,15 @@ export function QueryList<T>(props: QueryListProps<T>) {
} }
} }
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.status === 'error') {
if (result.error instanceof Error) { if (result.error instanceof Error) {
return <Alert severity='error'>Error: {result.error.message}</Alert>; return <Alert severity='error'>Error: {result.error.message}</Alert>;