Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
if (isEnterKey(key)) {
const answer = value || defaultValue || '';
setStatus('loading');
const isValid = await config.validate(answer);
if (isValid === true) {
setValue(answer);
setStatus('done');
done(answer);
} else {
// TODO: Can we keep the value after validation failure?
// `rl.line = value` works but it looses the cursor position.
setValue('');
setError(isValid || 'You must provide a valid value');
setStatus('pending');
}
} else if (isBackspaceKey(key) && !value) {
setDefaultValue(undefined);
} else {
setValue(rl.line);
setError(undefined);
}
});