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

@worldware/msg-react

v1.1.3

Published

React components for rendering messages from @worldware/msg

Readme

msg-react

React components for rendering messages from @worldware/msg.

Installation

@worldware/msg is a peer dependency of @worldware/msg-react (and is marked external in the build). Install both packages in your app:

npm install @worldware/msg@^0.12.0 @worldware/msg-react

That keeps a single shared @worldware/msg instance and types in the dependency tree and avoids duplicate copies. On 0.x, caret ranges do not include the next minor, so install a @worldware/msg release that satisfies this package's peer (^0.12.0).

Components

MsgResourceProvider

Provides a MsgResource to descendants via React context. On mount, it resolves a language tag from the nearest ancestor with a lang attribute, or falls back to navigator.language, then calls resource.getTranslation(lang) and updates the context with the result.

| Prop | Type | Description | | --- | --- | --- | | resource | MsgResource | Message resource to expose and translate | | children | React.ReactNode | Tree that can consume the resource |

Also exports MsgResourceContext if you need to read the resource directly with useContext.

MsgMessage

Looks up a message by key from MsgResourceContext and renders it inside a <span> with lang and dir from the message attributes.

| Prop | Type | Description | | --- | --- | --- | | msgKey | string | Key of the message to render | | data | Record<string, any> (optional) | Values passed to message.format() | | options | MessageFormatOptions (optional) | Options forwarded to message.format() |

  • With data: calls message.format(data, options)
  • Without data: calls message.toString()
  • Missing key or null context: renders an empty <span>

Usage

Basic setup

Wrap your app (or a subtree) with MsgResourceProvider passing in an MsgResource instance, then render messages with MsgMessage:

import { MsgResource } from '@worldware/msg'
import { MsgResourceProvider, MsgMessage } from 'msg-react'

const resource = MsgResource.create(/* ... */)

function App() {
  return (
    <div lang="en">
      <MsgResourceProvider resource={resource}>
        <h1>
          <MsgMessage msgKey="greeting" data={{ name: 'Kat' }} />
        </h1>
      </MsgResourceProvider>
    </div>
  )
}

Format with data and options

Pass data (and optional options) to call message.format():

<MsgMessage
  msgKey="greeting"
  data={{ name: 'Kat' }}
  options={{ bidiIsolation: 'none' }}
/>

Plain message text

Omit data to render message.toString() instead:

<MsgMessage msgKey="welcome" />

Language resolution

MsgResourceProvider picks a language from the nearest ancestor with a lang attribute:

<div lang="fr">
  <MsgResourceProvider resource={resource}>
    <MsgMessage msgKey="greeting" data={{ name: 'Kat' }} />
  </MsgResourceProvider>
</div>

If no lang ancestor exists, it falls back to the navigator.language setting.

Read the resource from context

Use MsgResourceContext when you need the resource outside of MsgMessage:

import { useContext } from 'react'
import { MsgResourceContext } from 'msg-react'

function MessageCount() {
  const resource = useContext(MsgResourceContext)
  // use resource.get(...), etc.
  return null
}

Scripts

| Script | Description | | --- | --- | | npm test | Run tests once | | npm run test:watch | Run tests in watch mode | | npm run build | Bundle ESM + CJS (and types) to dist/ via tsup |