Expensify.cash - Implement Higher-Order Component that re-renders when the locale changes
See original GitHub issueWe are implementing the structure for internationalisation and localisation in Expensify.Cash. As part of that, we need to implement a Higher-Order Component that re-renders when the locale changes
This is similar to our withOnyx HOC. It’s the only place that needs to care when the preferredLocale NVP changes and when it does, it re-triggers rendering of any component using it. It will:
- Have one prop preferredLocale and its default will be
en
- Call withOnyx passing
{locale: {key: ONYXKEYS.PREFERRED_LOCALE}}
. ONYXKEYS.PREFERRED_LOCALE will have the valuepreferredLocale
- Do I need to handle anything in componentDidUpdate? I think not?
- It will pass as props to the WrappedComponent (the component that’s using it) each of the methods of the libraries defined above, but with the locale already passed (we can also make this just one property with all these methods in it. Something like
translations.methodName()
):
- translate(phrase, variables) which will use this
- numberFormat(options). It will return a new Intl.NumberFormat object for the current locale and using the options passed.
- timestampToRelative(timestamp) which will use this
- timestampToDateTime(timestamp, includeTimezone) which will use this
- toLocalPhone(number) which will use this
- fromLocalPhone(number) which will use this
Expensify/Expensify repo issue.
Issue Analytics
- State:
- Created 2 years ago
- Comments:16 (16 by maintainers)
Top Results From Across the Web
React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >appWithTranslation re-renders _app when the locale is changed
Bug Report Changing locale when using appWithTranslation causes the _app component to entirely re-render, causing adverse side effects.
Read more >Prevent a React component from re-rendering with a HOC
Higher -Order Component is a pattern in React invented by Sebastian ... states and forcing a component to re-render upon a state's change, ......
Read more >How to solve too many re-renders error in ReactJS?
These are some tips to avoid too many re-renders errors in React: Don't change the state in the main body of the component....
Read more >Untitled
Battute oscene, Avanade india salary, World's most expensive apartment japan, Bohimiyanuwa episode 1, 1980 enticer track size. Annabel dundon, Lokaal nieuws ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Looks great 👍
Oh nice! ok, I think we should go with that option then. @AndrewGable, @Julesssss do you agree?