반응형
1. 라이브러리 설치
yarn add @sanity/block-content-to-react
yarn add react-syntax-highlighter
2. BlogPostDetail.jsx
import {Col, Row } from 'antd'
import BlockContent from '@sanity/block-content-to-react'
import SyntaxHighlighter from 'react-syntax-highlighter'
const serializers = {
types: {
code: ({node}) => {
const { code } = node;
return (
<SyntaxHighlighter
language="javascript"
style={{"hljs": {color: 'red',}}}
>{code}</SyntaxHighlighter>
)
},
video: ({ node }) => {
return <p>video</p>
},
link: ({ node }) => {
return <p>link</p>
},
imageGallery: ({ node }) => {
return <p>imageGallery</p>
},
}
}
export default function BlogPostDetail({blocks}) {
return (
<>
<Col span={24}>
<BlockContent
blocks={blocks}
projectId= {process.env.SANITY_PROJECT_ID}
dataset="production"
serializers={serializers}
/>
</Col>
</>
)
}
반응형
'Programming > React' 카테고리의 다른 글
SWR로 로컬 상태 컨트롤 - Counter (0) | 2021.06.26 |
---|---|
Next.js 시작하기4 - 설정파일 (0) | 2021.06.20 |
Next.js 시작하기2 - 스타일링 (0) | 2021.06.20 |
Next.js 시작하기 (Sanity Blog 작성 완료된 경우) (0) | 2021.06.20 |
Recoil 따라하기 - TodoList (0) | 2021.05.28 |