Is it possible to call react-intl api methods without inject each component

397 Views Asked by At

i'm wondering if there's any way to call API methods without inject each component ?

somthing like providing a function that will call intl.formatMessage for example

export function t(id,defaultmessage){
console.log("Called ",id,defaultmessage);
return intl.formatMessage(
{
  id: id,
  defaultMessage: defaultmessage
 }
)
}
1

There are 1 best solutions below

1
On

I would look into a state management library such as Redux. The data would then be passed into each component as a property, instead of having an API call in each component.