Skip to content

How to use GraphQL queried data in SSR rendered html.js? #38930

Answered by violy
paulwellnerbou asked this question in Help
Discussion options

You must be logged in to vote

Have you try to use Head Api ?

I show you an example, using bootstrap css cdn, and a simple static query as a Proof of Concept…

First, create a DefaultHead component, like this

import React from "react";
import {graphql, HeadProps, useStaticQuery} from "gatsby";

export type DefaultHead<DataType = object, PageContextType = object> = (
    props: HeadProps<DataType, PageContextType> & { title?: string }
) => JSX.Element
const DefaultHead: DefaultHead<any,any> = (props) => {
    const { site: { siteMetadata } } = useStaticQuery(graphql`
        query DefaultHead {
            site {
                siteMetadata {
                    title
                }
            }
        }`);
    const 

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@violy
Comment options

@violy
Comment options

@paulwellnerbou
Comment options

@violy
Comment options

Answer selected by paulwellnerbou
@paulwellnerbou
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants