Last active
April 27, 2019 22:56
-
-
Save jasonmit/0f1bfa33fa2d75f4091dcaafd45a31e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const TaskInput = () => { | |
let [inputValue, setInputValue] = useState(''); | |
let [perform, taskState] = useTask(function*(newInputValue) { | |
setInputValue(newInputValue); | |
yield timeout(1000); | |
if (newInputValue) { | |
return [newInputValue]; | |
} | |
return []; | |
}); | |
return ( | |
<> | |
<input onChange={e => perform(e.target.value)} value={inputValue} /> | |
{taskState.lastSuccessful && ( | |
<ul> | |
{taskState.lastSuccessful.result.map((item, index) => ( | |
<li key={index}>{item}</li> | |
))} | |
</ul> | |
)} | |
</> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment