Skip to content

Cannot read properties of undefined (reading 'value') - i18n locales #98

Answered by csandman
belkocik asked this question in Q&A
Discussion options

You must be logged in to vote

Unlike the Chakra UI Select which is a wrapper for the native HTML <select> element, this component doesn't return a change event (with how you're getting e.target.value). It instead just returns the object itself from your list of options. So in order for this to work right, you'll need to change your changeLanguage function like so:

/**
 * newLanguage = {
 *    label: 'EN',
 *    value: 'en'
 *  }
 */

const changeLanguage = newLanguage => {
  const locale = newLanguage.value; // <-- just .value not .target.value
  router.push(router.pathname, router.asPath, { locale })
}

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by csandman
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #82 on May 05, 2022 19:21.