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-i18next-helpers

v1.0.1

Published

A set of helper hooks and components to use with i18next, react-i18next and Formik

Readme

react-i18next-helpers

A small set of compatibility helpers for apps that use React, Formik, i18next, and react-i18next.

Modern usage guidance

These helpers are for edge cases where translations live outside normal React rendering.

For most React UI, prefer calling t(...) during render or using Trans from react-i18next. For most Formik validation, prefer storing translation keys and values in form errors, then translating those errors during render. That approach re-renders naturally when the active language changes.

Use this package when an existing app stores already-translated Formik error strings, or when sanitized dynamic HTML contains data-i18n tokens that React does not render directly.

Installation

npm install react-i18next-helpers

Install the peer dependencies in your app:

npm install formik i18next react react-i18next

Translate Formik errors after language changes

Formik validation errors can stay in the previous language after i18n.changeLanguage() runs if validation stores translated strings instead of translation keys. useTranslateFormErrors re-touches fields that already have errors and have been touched, causing Formik to validate them again.

Use this helper for legacy or compatibility flows. In new code, prefer rendering errors from keys:

{formik.errors.name && <div>{t(formik.errors.name)}</div>}
import { Formik } from 'formik';
import { useTranslateFormErrors } from 'react-i18next-helpers';

const ContactForm = formik => {
  useTranslateFormErrors(formik.errors, formik.touched, formik.setFieldTouched);

  return (
    <form onSubmit={formik.handleSubmit}>
      <input
        type="text"
        name="name"
        onChange={formik.handleChange}
        onBlur={formik.handleBlur}
        value={formik.values.name}
      />
      {formik.errors.name && <div>{formik.errors.name}</div>}
      <button type="submit">Submit</button>
    </form>
  );
};

const Example = () => (
  <Formik initialValues={{ name: '' }} onSubmit={values => console.log(values)}>
    {formik => <ContactForm {...formik} />}
  </Formik>
);

You can also use WithTranslateFormErrors when you want a wrapper component:

import { Formik } from 'formik';
import { WithTranslateFormErrors } from 'react-i18next-helpers';

const Example = () => (
  <Formik initialValues={{ name: '' }} onSubmit={values => console.log(values)}>
    {formik => (
      <WithTranslateFormErrors form={formik}>
        <form onSubmit={formik.handleSubmit}>
          <input
            type="text"
            name="name"
            onChange={formik.handleChange}
            onBlur={formik.handleBlur}
            value={formik.values.name}
          />
          {formik.errors.name && <div>{formik.errors.name}</div>}
          <button type="submit">Submit</button>
        </form>
      </WithTranslateFormErrors>
    )}
  </Formik>
);

Translate dynamic HTML

useTranslateHtmlElement translates elements inside dynamic HTML that use a data-i18n attribute. This is intended for CMS or backend-provided HTML that React does not own directly.

For normal React content, prefer t(...) or Trans. Sanitize untrusted HTML before rendering it.

import DOMPurify from 'dompurify';
import { useTranslateHtmlElement } from 'react-i18next-helpers';

const SafeHtml = ({ html }) => {
  const [ref] = useTranslateHtmlElement(html);
  const safeHtml = DOMPurify.sanitize(html);

  return <div ref={ref} dangerouslySetInnerHTML={{ __html: safeHtml }} />;
};
<span data-i18n="profile.greeting"></span>