question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Expensify.cash - Implement Higher-Order Component that re-renders when the locale changes

See original GitHub issue

Upwork job posting

We 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:

  1. Have one prop preferredLocale and its default will be en
  2. Call withOnyx passing {locale: {key: ONYXKEYS.PREFERRED_LOCALE}}. ONYXKEYS.PREFERRED_LOCALE will have the value preferredLocale
  3. Do I need to handle anything in componentDidUpdate? I think not?
  4. 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:closed
  • Created 2 years ago
  • Comments:16 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
AndrewGablecommented, Apr 2, 2021

Looks great 👍

1reaction
iwizniacommented, Apr 2, 2021

Oh nice! ok, I think we should go with that option then. @AndrewGable, @Julesssss do you agree?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found