Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

use-wasm-ts

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

use-wasm-ts

Use WebAssembly in React in a simple way with hooks and Typescript!

  • 1.2.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-80%
Maintainers
1
Weekly downloads
 
Created
Source

use-wasm-ts

Version Build Size GitHub Workflow Status (with branch) GitHub

Use WebAssembly in React in a simple way with hooks and Typescript!

npm install use-wasm-ts

This package allows you to load and use your WebAssembly functions inside React easily.

Usage

import { FC } from 'react';
import { useWasm } from 'use-wasm-ts';

const MyComponent: FC = () => {
    const {
        isLoading,
        fn: { compute },
    } = useWasm<{ compute: (n: number) => number }>('compute.wasm');

	return (
        <>
            <p>{isLoading ? "Loading..." : `Loaded with ${compute(10)}`}</p>
        </>
    );
};

export default MyComponent;

Show a live demo on CodeSandbox.

API

useWasm

useWasm<T>(url: string, options?: useWasmOptions): {
    isLoading: boolean;
    fn: T;
    module: WebAssembly.Module;
    instance: WebAssembly.Instance;
    memory: WebAssembly.Memory;
};
url

Type: string

The url of the WebAssembly file.

options

Type: useWasmOptions

streaming: boolean (default: false)

The streaming option allows you to load the WebAssembly file in streaming mode. Before using it, make sure that your server serves the file with the correct MIME type.

fetchOptions: RequestInit (default: {})

The fetchOptions option allows you to pass options to the fetch function.

memory: WebAssembly.Memory (default: { initial: 256, maximum: 512 })

The memory option allows you to pass a custom memory to the WebAssembly file.

env: (memory: WebAssembly.Memory) => { [key: string]: any } (default: {})

The env option allows you to pass a custom environment to the WebAssembly file. The function takes the default / custom memory as an optionnal parameter and must return an object.

License

MIT

Keywords

FAQs

Package last updated on 25 May 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc