Created
December 30, 2022 22:15
-
-
Save kivircik-parantez/ad40acd6adcb0a34f4c076e1032de972 to your computer and use it in GitHub Desktop.
Sending a POST request
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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