File tree Expand file tree Collapse file tree 1 file changed +30
-7
lines changed
src/All Assessment/assessment19 Expand file tree Collapse file tree 1 file changed +30
-7
lines changed Original file line number Diff line number Diff line change 1- import React from 'react'
1+ import React , { useState , useEffect } from 'react' ;
22
33const Debouncing = ( ) => {
4+ const [ inputValue , setInputValue ] = useState ( '' ) ;
5+ const [ debouncedValue , setDebouncedValue ] = useState ( '' ) ;
6+
7+ useEffect ( ( ) => {
8+ const handler = setTimeout ( ( ) => {
9+ setDebouncedValue ( inputValue ) ;
10+ } , 300 ) ;
11+ return ( ) => {
12+ clearTimeout ( handler ) ;
13+ } ;
14+ } , [ inputValue ] ) ;
15+
16+ const handleChange = ( event ) => {
17+ setInputValue ( event . target . value ) ;
18+ } ;
19+
420 return (
5- < div >
6- < div > sameer</ div >
7-
21+ < div className = 'flex flex-col h-screen bg-gray-800/20 items-center justify-center' >
22+ < input
23+ className = 'bg-transparent border-2 border-gray-500 rounded-lg w-1/2 px-10 py-3'
24+ type = "text"
25+ value = { inputValue }
26+ onChange = { handleChange }
27+ placeholder = "Type something..."
28+ />
29+ < p > Input value: { inputValue } </ p >
30+ < p > Debounced value: { debouncedValue } </ p >
831 </ div >
9- )
10- }
32+ ) ;
33+ } ;
1134
12- export default Debouncing
35+ export default Debouncing ;
You can’t perform that action at this time.
0 commit comments