Closed suhyeoonn closed 3 months ago
useDebounce
delay
function App() { const [searchText, setSearchText] = useState(''); const [debouncedText, setDebouncedText] = useState(searchText); const handleChange = (e: ChangeEvent<HTMLInputElement>) => { const newValue = e.target.value; setSearchText(newValue); debounceSearchText(newValue); }; const debounceSearchText = useDebounce((text: string) => { setDebouncedText(text); }, 200); const filteredUsers = users.filter((u) => u.name.toLowerCase().includes(debouncedText.toLowerCase()) ); return ( <div> <input type="text" value={searchText} onChange={handleChange} /> <ul> {filteredUsers.map((u) => ( <li key={u.id}>{u.name}</li> ))} </ul> </div> ); }
πΎ Pull Request
1οΈβ£ Spec
useDebounce
ν μ μ£Όμ΄μ§ μ½λ°± ν¨μκ° μΌμ μκ°(delay
) λμ νΈμΆλμ§ μμ λκΉμ§ μ½λ°± ν¨μμ μ€νμ μ§μ°μν΅λλ€.2οΈβ£ λ³κ²½ μ¬ν
3οΈβ£ μμ μ½λ
4οΈβ£ κ΄λ ¨ λ¬Έμ (μ ν μ¬ν)