rsnext/examples/with-segment-analytics-pages-router/components/form.tsx
Luke Bussey 1aab5ee915
(Example) Update with-segment-analytics to use segmentio/analytics-next and app layout (#52327)
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>
2023-08-30 13:04:38 -05:00

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