Unique state in multiple instances of same component

Viewed 31

Is there a way to make useState not to share the state between multiple instances of the same component without hacking the key argument with Math.random().

const activated = useState("activated", () => false)
1 Answers

I'd suggest to use useState if you want to share state. If you don't want to, you could use const activated = ref(false). You must not use it outside the setup function though.

const activated = () => useState(false) would be another option (see https://v3.nuxtjs.org/guide/features/state-management).

Related