Reputation:
I'm using React and Nextjs, and I was having issues with my contact button. I want it so when someone clicks on my button, it should open up their mail with my email prefilled (pretty much the mailto functionality).
<Button onClick = {(href) => href - "mailto:[email protected]"}> Email </Button>
I can't seem to figure out why it won't work, on click the button doesn't do anything.
Upvotes: 0
Views: 6894
Reputation: 438
As said in the comments, you could achieve the same thing with a tag. Even though it is already answered, I want to share my answer too, hope it helps others.
You can achieve the same result with a button too. In order to do that you will have to call useRouter
hook from nextjs and then redirect user once they click on the button like so:
import { useRouter } from 'next/router'
export default function Page() {
const router = useRouter()
return (
<button type="button" onClick={() => router.push('mailto:[email protected]')}>
Click me
</button>
)
}
Upvotes: 2