I'm passing a custom link to serializeHyperlink in a component (per the Gatsby documentation) in order to open external links in a new tab, but nothing is rendered.
The component is a slice.
I can pass a target="_blank" with the htmlSerializer, but want the control over the links that serializeHyperlink is supposed to provide.
customLink.js:
import React from 'react'
import { Link } from 'gatsby'
import { linkResolver } from './linkResolver'
export const CustomLink = (type, element, content, children) => {
if (element.data.link_type === 'Document') {
<Link to={linkResolver(element.data)} key={element.data.id}>
{content}
</Link>
}
if (element.data.link_type === 'Media') {
<a href={element.data.url} target="_blank" rel="noopener noreferrer">
<strong>{content}</strong>
</a>
}
if (element.data.link_type === 'Web') {
<a href={element.data.url} target="_blank" rel="noopener noreferrer">
{content}
</a>
}
return null
}