Turns out the issue was related to boxes
and recipes
not yet being populated through useEffect
as I was trying to set the box after navigating. The solution was to add a dependency on these two states and setting the box only if these two have been set.
useEffect(() => {
if (state != undefined && boxes.length > 0 && recipes.length > 0) {
updateBox(state.barcode)
}
}, [state, boxes, recipes]);