Skip to content

Commit

Permalink
Batch state updates in useInput callback (#581)
Browse files Browse the repository at this point in the history
  • Loading branch information
vadimdemedes authored May 1, 2023
1 parent e4d4770 commit eed2a11
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/hooks/use-input.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {type Buffer} from 'node:buffer';
import {useEffect} from 'react';
import {isUpperCase} from 'is-upper-case';
import parseKeypress, {nonAlphanumericKeys} from '../parse-keypress.js';
import reconciler from '../reconciler.js';
import useStdin from './use-stdin.js';

/**
Expand Down Expand Up @@ -182,7 +183,10 @@ const useInput = (inputHandler: Handler, options: Options = {}) => {

// If app is not supposed to exit on Ctrl+C, then let input listener handle it
if (!(input === 'c' && key.ctrl) || !internal_exitOnCtrlC) {
inputHandler(input, key);
// @ts-expect-error TypeScript types for `batchedUpdates` require an argument, but React's codebase doesn't provide it and it works without it as exepected.
reconciler.batchedUpdates(() => {
inputHandler(input, key);
});
}
};

Expand Down

0 comments on commit eed2a11

Please sign in to comment.