usePreferredLanguage

Adapt to user language preferences dynamically with usePreferredLanguage.

Install:

npm i @uidotdev/usehooks

Description:

Basically, what this hook does is that, it takes a parameter with value true or false and toggles that value to opposite. It’s useful when we want to take some action into it’s opposite action, for example: show and hide modal, show more/show less text, open/close side menu.

Return Value

NameTypeDescription
preferredLangstringThe hook returns a string that represents the preferred language of the user, as set in the browser settings.

Demo:

Example:

Related Hooks: