I have a variable that is already setup from the API result, the value is an array:
tier_items = [{id:1, name:'coffee'}, {id:2, name:'tea'}, {id:2, name:'juice'}]
this tier_items value is always updated with this condition
useEffect(()=>{console.log('tier_items')}, [tier_items])
value after updated : tier_items = [{id:1, name:'coffee'}]
I need to get both the previous & current value of updated tier_items
const [current, setCurrent] = useState(tier_items)
const [previous, setPrevious] = ???
this is the expected result
current = [{id:1, name:'coffee'}]
previous = [{id:1, name:'coffee'}, {id:2, name:'tea'}, {id:2, name:'juice'}]
also the next upcoming value onwards