Home > Mobile >  What do both nulls mean in vue ref<HTMLButtonElement | null>(null)
What do both nulls mean in vue ref<HTMLButtonElement | null>(null)

Time:02-28

What do each of these nulls mean in vue ref?

const submitButton = ref<HTMLButtonElement | null>(null);

CodePudding user response:

The first null is part of the type (which is defined between angle brackets <>).

Meaning that the value of this ref() can be either a HTMLButton Element, or null.

The second null is the value of the ref that is initially being set.

So submitButton is a ref that can either be a buttonelement or null and it is currently null.

  • Related