Jan Veselý
Jan Veselý

Reputation: 1529

Unique state in multiple instances of same component

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)

Upvotes: 1

Views: 361

Answers (1)

some-user
some-user

Reputation: 4954

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://nuxt.com/docs/getting-started/state-management).

Upvotes: 0

Related Questions