1aab5ee915
The [with-segment-analytics](https://github.com/vercel/next.js/blob/canary/examples/with-segment-analytics) example is out of date so this PR updates it to use [segmentio/analytics-next](https://github.com/segmentio/analytics-next) with TypeScript and the app layout. --------- Co-authored-by: Lee Robinson <me@leerob.io>
46 lines
920 B
TypeScript
46 lines
920 B
TypeScript
import { useState } from 'react'
|
|
import { analytics } from '@/lib/segment'
|
|
|
|
export default function Form() {
|
|
const [message, setMessage] = useState('')
|
|
|
|
const handleSubmit = (e: React.FormEvent) => {
|
|
e.preventDefault()
|
|
analytics.track('Form Submitted', {
|
|
message,
|
|
})
|
|
setMessage('')
|
|
}
|
|
|
|
return (
|
|
<>
|
|
<form onSubmit={handleSubmit}>
|
|
<label>
|
|
<span>Message:</span>
|
|
<textarea
|
|
onChange={(e) => setMessage(e.target.value)}
|
|
value={message}
|
|
/>
|
|
</label>
|
|
<button type="submit">submit</button>
|
|
</form>
|
|
|
|
<style jsx>{`
|
|
label span {
|
|
display: block;
|
|
margin-bottom: 12px;
|
|
}
|
|
|
|
textarea {
|
|
min-width: 300px;
|
|
min-height: 120px;
|
|
}
|
|
|
|
button {
|
|
margin-top: 12px;
|
|
display: block;
|
|
}
|
|
`}</style>
|
|
</>
|
|
)
|
|
}
|