Skip to content

Instantly share code, notes, and snippets.

@jasonmit
Last active April 27, 2019 22:56
Show Gist options
  • Save jasonmit/0f1bfa33fa2d75f4091dcaafd45a31e8 to your computer and use it in GitHub Desktop.
Save jasonmit/0f1bfa33fa2d75f4091dcaafd45a31e8 to your computer and use it in GitHub Desktop.
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