Skip to content

Instantly share code, notes, and snippets.

@kivircik-parantez
Created December 30, 2022 22:15
Show Gist options
  • Save kivircik-parantez/ad40acd6adcb0a34f4c076e1032de972 to your computer and use it in GitHub Desktop.
Save kivircik-parantez/ad40acd6adcb0a34f4c076e1032de972 to your computer and use it in GitHub Desktop.
Sending a POST request
function Form() {
const [firstName, setFirstName] = useState('');
const [lastName, setLastName] = useState('');
// ✅ Good: This logic runs because the component was displayed
useEffect(() => {
post('/analytics/event', { eventName: 'visit_form' });
}, []);
function handleSubmit(e) {
e.preventDefault();
// ✅ Good: Event-specific logic is in the event handler
post('/api/register', { firstName, lastName });
}
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment