Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

debounce reactjs

//Wait 500ms before validating data
//This method is used to check if the user stopped typing
//This way the state does not change on every keystroke the user enters!
const [formIsValid, setFormIsValid] = useState(false);

useEffect(() => {
  setTimeout(() => {
    console.log('Checking form validity!');
    setFormIsValid(enteredEmail.includes('@') && enteredPassword.trim().length >6);
  }, 500);
}, [enteredEmail, enteredPassword]);
 
PREVIOUS NEXT
Tagged: #debounce #reactjs
ADD COMMENT
Topic
Name
6+8 =