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 }); | |
} | |
// ... | |
} |