Skip to content

Instantly share code, notes, and snippets.

@darisi
Created January 6, 2020 20:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save darisi/1f0ce71a2be1f447bd76df7d71803972 to your computer and use it in GitHub Desktop.
Save darisi/1f0ce71a2be1f447bd76df7d71803972 to your computer and use it in GitHub Desktop.
Sanity, Gatsby - Custom Block Style
import React from "react";
const Lead = ({ children }) => {
return <p className="text-2xl text-gray-600">{children}</p>;
};
export default Lead;
import React from "react";
import Figure from "./Figure";
import Lead from "./Lead";
const serializers = {
types: {
authorReference: ({ node }) => <span>{node.author.name}</span>,
mainImage: Figure,
block: ({ node, children }) => {
switch (node.style) {
case "h1":
return <h1>{children}</h1>;
case "h2":
return <h2>{children}</h2>;
case "h3":
return <h3>{children}</h3>;
case "h4":
return <h4>{children}</h4>;
case "blockquote":
return <blockquote>{children}</blockquote>;
case "lead":
return <Lead children={children} />;
default:
return <p>{children}</p>;
}
},
},
};
export default serializers;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment