You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
importReact,{useCallback,useState}from'react';import{render,Box}from'ink';importConfirmInputfrom'ink-confirm-input';constUnicornQuestion=()=>{const[answer,setAnswer]=useState();const[value,setValue]=useState('');consthandleSubmit=useCallback(submitValue=>{if(submitValue===false){setAnswer({answer: 'You are heartless…'});return;}setAnswer({answer: 'You love unicorns!'});},[setAnswer]);return(<Box>
Do you like unicorns? (Y/n)
<ConfirmInputisCheckedvalue={value}onChange={setValue}onSubmit={handleSubmit}/>{answer&&answer}</Box>);};render(<UnicornQuestion/>);
API
<ConfirmInput/>
Props
<ConfirmInput/> accepts the same props as <TextInput/> in addition to the ones below.
isChecked
Type: boolean
Whether to return true or false by default.
value
Type: string
Value to display in a text input.
placeholder
Type: string
Text to display when value is empty.
onChange
Type: Function
Function to call when value updates. Returns a string with the input.
onSubmit
Type: Function
Function to call when user press Enter. Returns a boolean for the answer.