Skip to content

Latest commit

 

History

History
55 lines (35 loc) · 997 Bytes

File metadata and controls

55 lines (35 loc) · 997 Bytes

tinky


tinky / useInput

Function: useInput()

useInput(inputHandler, options?): void

This hook is used for handling user input. It's a more convenient alternative to using StdinContext and listening for data events. The callback you pass to useInput is called for each character when the user enters any input. If the user pastes text, callback is called once with the whole string passed as input.

Parameters

inputHandler

InputHandler

The function to call when input is received.

options?

InputOptions = {}

Configuration options.

Returns

void

Example

import { render, useInput } from "tinky";

const UserInput = () => {
  useInput((input, key) => {
    if (input === "q") {
      // Exit program
    }

    if (key.leftArrow) {
      // Left arrow key pressed
    }
  });

  return null;
};

render(<UserInput />);