npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

react-mobx-i18next

v1.0.0

Published

A tiny i18n utility for MobX + React (mobx-react-lite) that replaces react-mobx-i18n. Includes @translatable decorator, withTranslatable HOC, and useTranslatable hook.

Readme

react-mobx-i18next

Use mobx + mobx-react-lite + i18next + react-i18next to completely replace react-mobx-i18n that is incompatible with react17+.

Install

npm i react-mobx-i18next                                       # this project
npm react react-dom i18next react-i18next mobx mobx-react-lite # required peer dependencies

# or
pnpm add react-mobx-i18next

React Class Component

Method 1: Context (RECOMMENDED)

We RECOMMENDs you to use this method because it can combine others contexts like UNSAFE_NavigationContext, UNSAFE_LocationContext together.

import React from 'react'
import { createRoot } from 'react-dom/client'
import { configure, makeAutoObservable } from 'mobx'
import { observer, Provider } from 'mobx-react'
import { UNSAFE_NavigationContext, UNSAFE_LocationContext } from 'react-router-dom'
import { createI18n, I18nStore, translatable, contextHubs, TranslatableContext } from 'react-mobx-i18next'

// Initialize i18n
const i18n = createI18n({ 
  lang: 'en', 
  fallbackLang: 'en', 
  resources: {
    en: { common: { hello: 'Hello, {{name}}!' } },
    zh: { common: { hello: 'Hello, {{name}}!' } },
  }
})

// Config MobX (if need)
configure({ enforceActions: "always" });

// Business Stores
class CounterStore {
  count = 0
  constructor() { makeAutoObservable(this) }
  inc = () => { this.count++ }
}

// Business Components
@inject('i18nStore', 'counterStore')
@contextInjector()
@observer
class CounterView extends React.Component<any> {
  render() {
    return (
      <div> 
      <p>{ this.context.t('common:hello', { this.props.name }) } </p> 
      <button onClick = { this.props.counterStore.onInc } > + { this.props.counterStore.count } </button> 
      <button onClick = {() => this.props.i18nStore.setLocale('zh')}> CN </button>
      <button onClick = {() => this.props.i18nStore.setLocale('en')}> EN </button> 
    </div> 
    )
  }
}

// Root Component
@contextHubs(TranslatableContext, UNSAFE_NavigationContext, UNSAFE_LocationContext)
@observer
class App extends React.Component<any> {
  constructor {
    this.store = { 
      i18nStore: new I18nStore(i18n)   // mobx language store
      counterStore: new CounterStore() // business store 
    }
  }
  render() {
    return (
      <Provider {...this.store}>
        <BrowserRouter>
          <CounterView name="Chris" />
        </BrowserRouter>
      </Provider>
    )
  }
}

// Boot react app
createRoot(document.getElementById('root')!).render(<App />)

Method 2: Decorator

import React from 'react'
import { observer, translatable } from 'react-mobx-i18next'

@translatable('common')
@observer
class Hello extends React.Component<any> {
  render() {
    return <h1>{ this.t('hello', { name: 'Chris' }) }</h1>
  }
}

Method 3: HOC

import React from 'react'
import { observer, withTranslatable } from 'react-mobx-i18next'

class Hello extends React.Component<any> {
  render() {
    return <h1>{ this.t('hello', { name: 'Chris' }) }</h1>
  }
}

export default withTranslatable('common')(observer(Hello))

React Function Component

Method 1 : Hook

import React from 'react'
import { observer, useTranslatable } from 'react-mobx-i18next'

const Hello = observer((props) => {
  const { i18n, t, ready } = useTranslatable('common')
  return <h1>{ t('hello', { name: 'World' }) } </h1>
})

Comparison with react-mobx-i18n

  • class component: @translatable → @translatable()
  • HOC: withTranslatable()
  • Hook: useTranslatable()
  • t() Behavior: Provided by react-i18next, supports ns:key or configurable via the ns option
  • I18nProvider: (Optional) When to use? You will need to use the provider if you need to support multiple i18next instances, otherwise no need it.
  • Language Switching: Call i18nStore.setLocale(lang) will trigger i18next switching and responsively update components