Next.js Discord

Discord Forum

i18n next breaks useState if `args/options` property is undefined on typescript

Unanswered
Pacific cod posted this in #help-forum
Open in Discord
Pacific codOP
Yes, first thing you thought was "There's no way".
The title is not wrong, here's my basic example.

const [showShadow, setShowShadow] = useState(false)

{JSON.stringify(showShadow)}
<button onClick={()=> { 
  console.log('PRESSED')
  setShowShadow(true)
}}>TEST</button>


I have the 'use client' directive at the top of the file.
This component is being imported in my root layout.

Pressing the TEST button outputs PRESSED like it should on console but the state will not change.

Package versions:
"next": "^13.4.7",
"react": "18.2.0",
"react-dom": "18.2.0",
"typescript": "^5.1.3"


edit: the options property from useTranslate should throw error if it's undefined, but for some reason nextjs just doesn't show the error overlay and useState breaks.

The solution was to make it nullable on the client version of the function. The problem only happens with typescript since it's the type checking that should output the error.

thx everyone

6 Replies

feel free to change this sandbox to show the error so I can give it a look
Pacific codOP
I didn't expect this to not work for me either.
I can't for the life of me figure out why it's behaving like that.

other client hooks like useEffects works just like it should but useState doesn't
Pacific codOP
update: i found the issue
it lies withing i18next
somehow i18next breaks the useState for the whole app if a single component imports it
my i18 code looked exactly like the docs for nextj13 (basically copy pasta)