debouce pushing changes to server

This commit is contained in:
SrGooglo 2024-09-15 17:45:40 +00:00
parent bf58669117
commit df88991bdf

View File

@ -1,7 +1,12 @@
import React from "react"
import lodash from "lodash"
import UserModel from "@models/user"
const pushToServer = lodash.debounce(async (update) => {
return await UserModel.updateConfig(update)
}, 500)
export default (props = {}) => {
const [firstLoad, setFirstLoad] = React.useState(true)
const [localData, setLocalData] = React.useState({})
@ -18,8 +23,8 @@ export default (props = {}) => {
props.onUpdate(localData)
}
const config = await UserModel.updateConfig(update)
setLocalData(config)
setLocalData(update)
pushToServer(update)
}
return [