Skip to content

Instantly share code, notes, and snippets.

@gustav1105
Created February 17, 2020 04:33
Show Gist options
  • Save gustav1105/acd65fd709e83bd70df2f9565b1ba1cb to your computer and use it in GitHub Desktop.
Save gustav1105/acd65fd709e83bd70df2f9565b1ba1cb to your computer and use it in GitHub Desktop.
composite-decorator
import * as React from "react";
import { EditorContext } from "./EditorContext";
export function DecoratedLink({
className,
children,
entityKey,
target
}: {
className: string;
children: React.ReactNode;
entityKey: string;
target?: string;
}) {
const editorState = React.useContext(EditorContext);
const entity = editorState.getCurrentContent().getEntity(entityKey);
const entityData = entity ? entity.getData() : undefined;
const href = (entityData && entityData.url) || undefined;
return (
<a
className={className}
title={href}
href={href}
target={target}
rel="noopener"
>
{children}
</a>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment