-
-
Notifications
You must be signed in to change notification settings - Fork 619
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
React Hooks #137
Comments
rough draft const useKeyHandler = keyHandler => { const { stdin, setRawMode } = useContext(StdinContext) useEffect(() => { setRawMode(true) stdin.on('data', keyHandler) return () => { stdin.off('data', keyHandler) setRawMode(false) } }, [stdin, setRawMode]) }
useKeyHandler(data => { if (data === 's') setSyncing(syncing => !syncing) if (data === 'p') setCreature(ascii()) if (data === 'q') process.exit(0) }) |
What would useStdin expose ideally, beyond something like |
In |
I have a import { useEffect } from 'react';
import { useApp } from 'ink';
export class ExitError extends Error {
public code: number;
constructor(code: number, message?: string) {
super(message);
this.code = code;
}
}
export const useExit = (error?: Error) => {
const { exit } = useApp();
useEffect(() => {
exit(error);
}, [exit]);
}; Don't know if the Happy to PR this if you want it. |
I don't think there's a benefit to having |
Fair. This issue might be worth closing now that the first batch is in. |
I'm opening this issue so we can discuss how Ink could take advantage of React Hooks.
For example, maybe
useStdin()
instead of<StdinContext>
?The text was updated successfully, but these errors were encountered: