score:2

Accepted answer

like @clarity said, push returns index of pushed item, also this operator mutates object. best practice is to create another array (eg. by spreading previous value, like suggested), and add a new entry there, like so:

setstate({menuhistory: [...state.menuhistory, location]});

score:1

you have defined {menuhistory: ['first']} which is array . try using concat instead of push.

   setstate({menuhistory: state.menuhistory.concat(location)});

score:2

push return an index of element, use array spread to add the item:

setstate(state => ({menuhistory: [...state.menuhistory, location]}));

Related Query

More Query from same tag