1

Keep getting above error, i've looked at other solutions but they don't seem to be working. Would appreciate some insight on what im missing. I read a getter needs a setter but im not sure how i would even include that in a basic fetch call.

I am using react and trying to fetch a blog post from contentful.

My code is below

import React from 'react'
import { useState, useEffect } from 'react'
import { createClient } from 'contentful'


const client = createClient=({
  space:"xxxxxxxxx",
  access_token:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
})

function App() {

  const [blog, setBlog] = useState([])

  useEffect=(()=> {
    const BlogPosts = async () => {
      try{
        await client.getEntries().then((entries)=> {
          console.log(entries);
          setBlog(entries)
        })
      } catch (err){
        console.log(err)
      }
      
    }
BlogPosts()


  }, [])
  return (
    <div>App</div>
  )
}

export default App
someone
  • 661
  • 1
  • 9
  • 26
  • You have 1 equals (`=`) too many probably. I doubt that you mean `client = createClient = bla` – Evert May 21 '23 at 18:11

1 Answers1

0

createClient is a function that takes in the credentials as params. You need to update your code as follows:

const client = createClient({
  space:"xxxxxxxxx",
  access_token:"xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
})

Here you can find the documentation for the JavaScript that you are using: https://www.contentful.com/developers/docs/javascript/tutorials/using-js-cda-sdk/

harshil1712
  • 156
  • 4