Destructuring with an alias

Destructuring with an alias

Normal Desctructring:

const { isValid} = emailState;
  • Same as : const isValid = emailState.isValid ;*

Destructuring with an alias

const { isValid: emailIsValid } = emailState;
  • Same as : const emailIsValid = emailState.isValid ;*

So this is an alias assignment. This is not a value assignment, it's an alias assignment because it's part of this object de-structuring syntax which is the syntax you're automatically using if you're using those curly braces on the left side of the equal sign. This can be useful when you need to destructure a value that has a similar or same name as an existing variable.

In modern javascript we can use this shortcut:

return { isLoading , error  }

instead of

return { isLoading : isLoading , error : error }