Home

Published

- 1 min read

wait for user input reactjs

img of wait for user input reactjs

The solution for this is noted below

wait for user input reactjs

Solution

   import React, { useEffect, useState } from 'react'

function App() {
	const [query, setQuery] = useState('')
	const [displayMessage, setDisplayMessage] = useState('')

	useEffect(() => {
		const timeOutId = setTimeout(() => setDisplayMessage(query), 500)
		return () => clearTimeout(timeOutId)
	}, [query])

	return (
		<>
			<input type='text' value={query} onChange={(event) => setQuery(event.target.value)} />
			<p>{displayMessage}</p>
		</>
	)
}

Try other methods by searching on the site. That is if this doesn’t work