I have an input box that when a user puts in information in it.
There is a lag time until the letters are populated correctly in the input box
The reason is that there’s some kind of a function in the background that takes a lot of resources to calculate the information in the input box.
In my case the function name is
onEditData({ field, id, value})
In order to bypass this issue I decided to use the new feature in React 18
useDeferredValue
however when a user types text in the input box nothing changes.
I am not sure what I did wrong?
You can find my code at
function CheckBreakdown() {
const [checkRegular, setCheckRegular] = useState([])
const deferredCheckRegular = useDeferredValue(checkRegular)
useEffect(() => {
setCheckRegular(obj.CheckRegular)
}, [])
// a breakdown of the check info
const handleChange = (e) => {
setCheckRegular(e.target.value)
let field = 'CheckRegular'
onEditData({ field, id, value: deferredCheckRegular })
}
return (
<div className="inPutSalesTable">
<div >
<Form.Label htmlFor="regularCheck#">Regular check #</Form.Label>
<Form.Control
type="text"
id="regularCheck#"
value={deferredCheckRegular}
field="CheckRegular"
onChange={handleChange}
/>
</div>
<div>
<Form.Label htmlFor="vatCheck#">Vat check #</Form.Label>
<Form.Control
value="John"
type="text"
id="vatCheck#"
/>
</div>
</div>
)
}
Thank you for your help