Kentico/gatsby-source-kontent

View on GitHub
examples/dsg-ssr/src/components/articleListing.js

Summary

Maintainability
A
0 mins
Test Coverage
import React from "react"
import { useStaticQuery, graphql, Link } from "gatsby"

export default function ArticleListing({ prefix }) {
  const data = useStaticQuery(graphql`
    query ArticlesQuery {
      allKontentItemArticle {
        nodes {
          id
          elements {
            slug {
              value
            }
            title {
              value
            }
          }
        }
      }
    }
  `)

  return (
    <ul>
      {data.allKontentItemArticle.nodes?.map(node => (
        <li key={node.id}>
          <Link to={`/${prefix}/${node.elements.slug.value}`}>
            {node.elements.title.value}
          </Link>
        </li>
      ))}
    </ul>
  )
}