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'

ReactDOM.render(
  <React.StrictMode>
    <ConfigProvider locale={i18n.languages[0]}>
      <App />
    </ConfigProvider>
  </React.StrictMode>,
  document.getElementById('root'),
)
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)

Collapse
 
benjioe profile image
Benjioe

Can you put your code in a CodeSandbox ?

Collapse
 
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!!

Top Posts from the React Ecosystem

1. Changes In The Official React Documentation

The former React Docs Beta has been officially released as the updated React documentation at react.dev after years of hard work and refinement. Check out the brand new React Docs: What’s New in the Updated React Docs

2. CRA's Time is Over

React developer team has removed create-react-app (CRA) from official documentation rendering it no longer the default setup method for new projects. The bulky setup, slow, and outdated nature of CRA led to its removal: create-react-app is officially dead

3. How to Fetch Dev.to Articles for Your Portfolio

Integrate the articles of your Dev.to profile into your personal portfolio with either React, Vue, or Next.js by following these simple steps. It outlines how to include frontend to pull the information and correctly utilizes the Dev.to API: How to Fetch Your Dev.to Articles for Your Portfolio with React