Skip to content

Commit

Permalink
fix(gui): correct react update during render
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Feb 11, 2023
1 parent 44c9524 commit 3c7a3e5
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions 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 {
Expand Down Expand Up @@ -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.error instanceof Error) {
return <Alert severity='error'>Error: {result.error.message}</Alert>;
Expand Down

0 comments on commit 3c7a3e5

Please sign in to comment.