diff options
author | Anton Tananaev <anton@traccar.org> | 2024-05-25 17:58:13 -0700 |
---|---|---|
committer | Anton Tananaev <anton@traccar.org> | 2024-05-25 17:58:13 -0700 |
commit | afafc146475e1c9219c7c48f1cb9c7f027d90940 (patch) | |
tree | 7c821e6529b7854db8834f3f3d874721030a6338 /src | |
parent | 8d36af23bf420a414fd70f0570bd414a0a069a8f (diff) | |
download | trackermap-web-afafc146475e1c9219c7c48f1cb9c7f027d90940.tar.gz trackermap-web-afafc146475e1c9219c7c48f1cb9c7f027d90940.tar.bz2 trackermap-web-afafc146475e1c9219c7c48f1cb9c7f027d90940.zip |
Fix select field with data
Diffstat (limited to 'src')
-rw-r--r-- | src/common/components/SelectField.jsx | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/common/components/SelectField.jsx b/src/common/components/SelectField.jsx index db8c30b0..de9dedce 100644 --- a/src/common/components/SelectField.jsx +++ b/src/common/components/SelectField.jsx @@ -1,7 +1,7 @@ +import React, { useEffect, useState } from 'react'; import { FormControl, InputLabel, MenuItem, Select, Autocomplete, TextField, } from '@mui/material'; -import React, { useState } from 'react'; import { useEffectAsync } from '../../reactHelper'; const SelectField = ({ @@ -17,7 +17,7 @@ const SelectField = ({ keyGetter = (item) => item.id, titleGetter = (item) => item.name, }) => { - const [items, setItems] = useState(data); + const [items, setItems] = useState(); const getOptionLabel = (option) => { if (typeof option !== 'object') { @@ -26,6 +26,8 @@ const SelectField = ({ return option ? titleGetter(option) : emptyTitle; }; + useEffect(() => setItems(data), [data]) + useEffectAsync(async () => { if (endpoint) { const response = await fetch(endpoint); |