Gatsby/React noob here.
I have created a content type called Topic in Contentful. Each Topic contains a title, desc, and slug to the topic page. Currently, I am able to render each topic as a card on the page. What I am trying to figure out now is how to render only one card at a time and have the card content (title/desc) randomly change when clicking the spin button.
I created this quick demo to show what I am going for visually.
Here is where I am rendering each topic card:
import React from 'react'
import { graphql, navigate, StaticQuery } from 'gatsby'
import './topicFeed.scss'
export default () => (
<StaticQuery
query={graphql`
query TopicFeed {
allContentfulTopic(filter: {featured: {eq: true}}) {
edges {
node {
cardDescription {
cardDescription
}
cardTitle
id
slug
}
}
}
}
`}
render={data => (
<div>
<div className='feed'>
{data.allContentfulTopic.edges.map(edge => (
<div key={edge.node.id} className='topic__item'>
<h2 className='card__title'>{edge.node.cardTitle}</h2>
<div className="card__desc--container">
<p className='card__desc'>{edge.node.cardDescription.cardDescription}</p>
</div>
<div className='card__link' onClick={() => navigate(`/topic/${edge.node.slug}`)}>
<p>Learn More</p>
</div>
</div>
))}
</div>
<button onClick={() =>console.log('werked')}onClick={() =>console.log('werked')}>SPIN</button>
</div>
)}
/>
)
It's my understanding that gatsby renders the divs for each card on build so I am confused about how that data can be manipulated onClick by the user.