I am making a reusable component in a Gatsby blog to go at the end of blog articles which takes the authorName of the article, and renders an 'About the Author' section, pulling the info from the author's bio stored elsewhere on the site.
I have made the component which works when the authorName is hard coded as a string, but I am stuck on how to get the author name from the article component (passed as props.author) into the GraphQl query.
I can confirm that: 1. The prop author is being passed correctly and console logs exactly right 2. The correct bio information and profile image is being pulled from the team bios according to the hard coded string author name
The missing link is to replace the hardcoded author name string with props.author
Thanks in advance for your help; I've reviewed similar questions and can't find the answer.
This is my component:
AboutAuthor.js
import React from "react";
import { StaticQuery, graphql } from "gatsby";
import Img from "gatsby-image";
export default (props) => (
<div>
<StaticQuery
query={graphql`
query {
copy: markdownRemark(
frontmatter: { name: { eq: "need to replace this string with props.author" } }
) {
html
frontmatter {
name
profileImage {
childImageSharp {
fluid(maxWidth: 800) {
...GatsbyImageSharpFluid
}
}
}
}
}
}
`}
render={data => (
<React.Fragment>
<p>Testing Name: {props.author}</p> // testing the author name is passed ok, will be removed
<Img
fluid={data.copy.frontmatter.profileImage.childImageSharp.fluid}
alt=""
/>
<div>
<span>
{data.copy.frontmatter.name}
</span>
<div
dangerouslySetInnerHTML={{ __html: data.copy.html }}
/>
</div>
</React.Fragment>
)}
/>
</div>
);
postAuthordata from its parent component instead