Setup Contentful Javascript SDK in React Native

468 views Asked by At

I'm trying to implement Contentful Javascript SDK on a React Native project (without Expo).

This is the code:

const {createClient} = require('contentful/dist/contentful.browser.min.js')

useEffect(() => {
    getContentfulData()
}, [])

const getContentfulData = async () => {
    var client = createClient({
    adapter: (config) => {
        config.adapter = null
        return fetch(config)
    },
    space: '---',
    accessToken: '---',
    })

    await client
        .getEntries()
        .then((entries) => {
            console.log(entries)
        })
        .catch((error) => {
            console.log(error)
        })
}

But I'm getting TypeError: Network request failed over and over again.

Any ideas?

1

There are 1 answers

0
Stefan T On
const { createClient } = require('contentful/dist/contentful.browser.min.js')

  const client = createClient({
    space: '*********',
    accessToken: '****************************************',
  })

    client
      .getEntries({
        content_type: 'trendingBlogs',
      })
      .then(entry => console.log(entry))
      .catch(err => console.log(err))

your missing the getEntries parameters. i.e

{
  content_type: 'trendingBlogs',
}