Skip to content

Passing MDText in the React 16.3+ Context

Choose a tag to compare

@alexdrel alexdrel released this 31 Mar 15:59
· 3 commits to master since this release

MDText object can be passed around using new official react context API.

import { MDText } from 'i18n-react';
let MDTextContext = React.createContext();
let Texts = new MDText({...});

<MDTextContext.Provider value={Texts}>
    <MDTextContext.Consumer>{ (T) =>
      <T.span text="path.to.string" />
    }</MDTextContext.Consumer>
</MDTextContext.Provider>

See updated examples/yaml for complete example.