NuxtN
Nuxt2y ago
22 replies
Tumulte

Does useState() a default value when the state key already set ?

The doc is unclear on the topic and my tests show contradictory results.

Let's say I call a component multiple times with


//component A

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'toto';

//component B

const foo = useState('foo', ()=>{user: null})
foo.value.user = 'bar';


will the second useState() be reset to {user: null} then to {user: 'bar'}

or is useState smart enough to know it aleady has a value and to not reinstantiate itself ?
Was this page helpful?