react-webserial-hook
v0.0.1
Published
A React Hook for WebSerial API
Downloads
1
Readme
@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>
)
}