Skip to content

Commit

Permalink
fix: always update fields when resolveData runs
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvxd committed Nov 14, 2024
1 parent 91bc97a commit 39dd619
Showing 1 changed file with 3 additions and 12 deletions.
15 changes: 3 additions & 12 deletions packages/core/components/AutoField/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -236,13 +236,11 @@ export function AutoFieldPrivate<
Label?: React.FC<FieldLabelPropsInternal>;
}
) {
const { state } = useAppContext();
const { value, onChange } = props;

const [localValue, setLocalValue] = useState(value);

const [recentlyChanged, setRecentlyChanged] = useState(false);
const timeoutRef = useRef<NodeJS.Timeout>();

const onChangeDb = useDebouncedCallback(
(val, ui) => {
onChange(val, ui);
Expand All @@ -254,19 +252,12 @@ export function AutoFieldPrivate<
const onChangeLocal = useCallback((val: any, ui?: Partial<UiState>) => {
setLocalValue(val);

setRecentlyChanged(true);

clearTimeout(timeoutRef.current);

timeoutRef.current = setTimeout(() => {
setRecentlyChanged(false);
}, RECENT_CHANGE_TIMEOUT);

onChangeDb(val, ui);
}, []);

useEffect(() => {
if (!recentlyChanged) {
// Prevent global state from setting local state if this field is focused
if (state.ui.field.focus !== props.name) {
setLocalValue(value);
}
}, [value]);
Expand Down

0 comments on commit 39dd619

Please sign in to comment.