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 πŸ™

Β© 2025 – Pkg Stats / Ryan Hefner

react-native-webassembly

v0.3.3

Published

βš›οΈ 🏎 WebAssembly for React Native JSI.

Readme

react-native-webassembly

This package enables WebAssembly for React Native powered by C++ TurboModules and Wasm3, a fast and universal WebAssembly runtime.

react-native-webassembly provides React Native applications with the capability to execute universal Wasm binaries with native speed.

✏️ This project is still in active development. The following tasks are still remaining to be completed:

  • Sanitize C++ memory management practices.
  • Normalize execution and result handling of userland export functions.
  • Test framework implementation.

Pull Requests are welcome! πŸ™

πŸ“‘ Installation

  1. First, ensure your React Native application supports the New Architecture:

  2. Install react-native-webassembly:

    yarn add react-native-webassembly # React Native
    npx expo install react-native-webassembly # Expo
  3. If you're using Expo, don't forget to run npx expo prebuild after installing.

✍️ Usage

The goal of react-native-webassembly is to export a browser-equivalent interface to the WebAssembly API.

To initialize a new WebAssembly module, we'll need to instantiate an module using a buffer populated with a .wasm binary:

import axios from 'axios';
import * as WebAssembly from 'react-native-webassembly';

import HelloWorld from './hello-world.wasm';

const module = await WebAssembly.instantiate<{
  add: (a: number, b: number) => number;
}>(HelloWorld);

Note

To import .wasm files directly, you will need to update your metro.config.js.

Alternatively, in the snippet below, we show how to download and instantiate the reference Hello World example stored at a remote location:

import axios from 'axios';
import * as WebAssembly from 'react-native-webassembly';

const {
  data: bufferSource,
} = await axios({
  url: 'https://github.com/torch2424/wasm-by-example/raw/master/examples/hello-world/demo/assemblyscript/hello-world.wasm',
  method: 'get',
  responseType: 'arraybuffer',
});

const module = await WebAssembly.instantiate<{
  add: (a: number, b: number) => number;
}>(bufferSource);

You'll notice that in our call to instantiate, we can also pass typing information for the Exports of the module. In this case, the hello-world.wasm binary exports a function to add two numbers, add.

Once configured, we can execute the compiled wasm module from our JavaScript code, using the type-safe exported interface:

module.instance.exports.add(1, 2); // 3.

It's also possible to declare an importObject to receive callbacks from the compiled module, which declares a list of callback function implementations which can be invoked by the WebAssembly runtime.

Warning

Some native modules require the presence of certain function implementations. Without specifying module-specific required dependencies, instantiation will fail.

For example, the Circom library converts arithmetic circuits used for generating, evaluating and verifying SNARKs are expressed as WASM modules which require the runtime to define an exceptionHandler function belonging to the namespace runtime.

It's simple to define an importObject:

const module = await WebAssembly.instantiate<{
  getVersion: () => number;
  getFieldNumLen32: () => number;
  // ...
}>(bufferSource, {
  // Declare custom memory implementation.
  env: {
    memory: new WebAssembly.Memory({ initial: 32767 }),
  },
  // Define the scope of the import functions.
  runtime: {
    exceptionHandler: (value: number) => console.error(value),
  },
});

Here, we declare an exceptionHandler as runtime imports to the compiled module. Without declaring this required dependency, the module would fail to compile.

You can find a working implementation of this process in the Example App.

πŸ€” Memory

Currently, wasm3 only supports a single memory region. This means that WebAssembly files which contain multiple memory allocations are not currently supported.

react-native-webassembly exposes access to the runtime memory element for allocated instances, which is represented using an ArrayBuffer named memory. This shares the same backing array as the native runtime.

It can accessed as follows:

const module = WebAssembly.instantiate(...);

const memory: ArrayBuffer | undefined = module.instance.exports.memory;

✌️ License

MIT