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

391 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 answers

1
Chad 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.