Hi there,
I'm having some trouble getting my image to render consistently. The problem is that my state is not updating on initial load and stays null, but if i can get it to re-render the image will appear successfully. I've triple checked my component with the docs and all the examples, as well as replaced my api token to make sure I didn't mis-type anything, but I am completely stumped. Any help would be greatly appreciated.
image code:
function HeaderImage() {
const [doc, setDocData] = useState(null)
useEffect(() => {
const fetchData = async () => {
const response = await Client.query(
Prismic.Predicates.at('document.type', 'landing_image')
).catch(console.error)
if(response) {
setDocData(response.results[0])
}
}
fetchData()
}, [])
return(
<header>
<NavMenu />
<img src={doc.data.header_image.url} alt={doc.data.header_image.alt} className='header-image'/>
</header>
)
}
export default HeaderImage