0.0.1 • Published 5 months ago

react-webserial-hook v0.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
5 months ago

@mniota/react-webserial-hook

A React Hook for WebSerial API

Install

npm i @mniota/react-webserial-hook

Usage

For more options, check the API autocomplete in your IDE:

import { useWebSerial } from "@mniota/react-webserial-hook"

function Component() {
  const serial = useWebSerial({
    onData: data => {
      const decored = new TextDecoder();
      console.log(decoder.decode(data));
    }
  })

  return (
    <div>
      <button onClick={() => serial.requestPort()}>
        Pair a new port
      </button>
      <button onClick={() => serial.openPort()}>
        Open the selected port
      </button>
      <button onClick={() => serial.startReading()}>
        Start reading
      </button>
    <div>
    )
}
0.0.1

5 months ago