reduce updates on fileList component

fix issue for file selection modal
This commit is contained in:
btzr-io 2020-05-15 00:00:25 -05:00 committed by Sean Yesmunt
parent 83da11b915
commit 2260f665c7

View file

@ -28,12 +28,23 @@ function FileList(props: Props) {
const first = radio.stops[0].ref.current; const first = radio.stops[0].ref.current;
// First auto-selection // First auto-selection
if (first && first.id === radio.currentId && !radio.state) { if (first && first.id === radio.currentId && !radio.state) {
const file = getFile(first.value);
// Update state and select new file
onChange(file);
radio.setState(first.value); radio.setState(first.value);
} }
if (onChange && radio.state && radio.state !== '') { if (radio.state) {
const file = getFile(radio.state); // Find selected element
const stop = radio.stops.find(item => item.id === radio.currentId);
const element = stop && stop.ref.current;
// Only update state if new item is selected
if (element && element.value !== radio.state) {
const file = getFile(element.value);
// Sselect new file and update state
onChange(file); onChange(file);
radio.setState(element.value);
}
} }
} }
} }