Skip to content

Commit

Permalink
fix: clean up useEffect dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
tomzemp committed Dec 20, 2024
1 parent 6b550ae commit de622f2
Show file tree
Hide file tree
Showing 8 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/boolean-radios.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export const BooleanRadios = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const { mutate } = useSetDataValueMutation({ deId, cocId })

Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/date-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export const DateInput = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const { data: userInfo } = useUserInfo()
const keyUiLocale = userInfo?.settings?.keyUiLocale
Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/datetime-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ export const DateTimeInput = ({
const dateWithTime = convertToDateWithTime({ date, time })
setValueSynced(dateWithTime === lastSyncedValue)
}
}, [date, time, lastSyncedValue, syncTouched])
}, [date, time, lastSyncedValue, syncTouched, setValueSynced])

const { mutate } = useSetDataValueMutation({ deId, cocId })

Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/file-inputs.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export const FileResourceInput = ({
)
}
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const dataValueParams = useDataValueParams({ deId, cocId })
const fileLink = useFileInputUrl(dataValueParams)
Expand Down
11 changes: 7 additions & 4 deletions src/data-workspace/inputs/generic-input.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export const GenericInput = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const limits = useMinMaxLimits(deId, cocId)

Expand All @@ -75,9 +75,12 @@ export const GenericInput = ({

// check if the initial value has any associated warnings
useEffect(() => {
const warningValidationResult = warningValidator(value)
setWarning(fieldname, warningValidationResult)
}, [initialValue, warningValidator, setWarning, fieldname])
// only check if the value has not been updated (i.e. is initial value)
if (!syncTouched) {
const warningValidationResult = warningValidator(value)
setWarning(fieldname, warningValidationResult)
}
}, [value, syncTouched, warningValidator, setWarning, fieldname])

const { mutate } = useSetDataValueMutation({ deId, cocId })

Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/long-text.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export const LongText = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const { mutate } = useSetDataValueMutation({ deId, cocId })
const syncData = (newValue) => {
Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/option-set.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ export const OptionSet = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const { mutate } = useSetDataValueMutation({ deId, cocId })
const syncData = (newValue) => {
Expand Down
2 changes: 1 addition & 1 deletion src/data-workspace/inputs/true-only-checkbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export const TrueOnlyCheckbox = ({
if (syncTouched) {
setValueSynced(value === lastSyncedValue)
}
}, [value, lastSyncedValue, syncTouched])
}, [value, lastSyncedValue, syncTouched, setValueSynced])

const { mutate } = useSetDataValueMutation({ deId, cocId })
const syncData = (newValue) => {
Expand Down

0 comments on commit de622f2

Please sign in to comment.