Usage

The useLocale() hook is helpful for accessing the user’s locale based on their device settings in situations where you need the locale string.

You can simply invoke this hook to access the locale string and then pass it around as needed.

For example, if you’re working with a package that handles translations separately (like plaid or react-native-date-picker), you may have to provide the locale to their components.

import React, { useState } from 'react'
import DatePicker as RNDatePicker from 'react-native-date-picker'
import { useLocale } from '@lexiconjs/react'

export const DatePicker = () => {
  const [date, setDate] = useState(new Date())
  // Example values: en-US, es-ES, etc
  const { locale } = useLocale()

  return (
   <RNDatePicker 
     locale={locale} // Pass it down to other libraries
     date={date} 
     onDateChange={setDate} 
   />
  )
}

Response

This hook returns the locale string.

locale
string

The user’s detected locale (based on their current device settings).

Example: en-US