DEV Community

Dennis Quesada Cruz
Dennis Quesada Cruz

Posted on

Changing AntD locale dynamically

Hello devs, it's new year and here i'm struggling with React and AntD.
I'm trying to change AntD locale dynamically. As documentation refers, AntD has a context that wraps , its receives 'lang' as a prop.
So here i'm doing this dumb thing:

import i18n from './i18n'

    <ConfigProvider locale={i18n.languages[0]}>
      <App />
Enter fullscreen mode Exit fullscreen mode

And of course, when i change the language nothing happens, the docs says that we have to set up a local state or so, but i'm really lost there. Any idea?

Top comments (2)

benjioe profile image

Can you put your code in a CodeSandbox ?

dcruz1990 profile image
Dennis Quesada Cruz

Thanks Benjioe, i did it. The thing is that i wasnt using a reactive variable to reffer the current lang, so never gets notified that something changed. Anyway thanks!!