Search code examples
node.jsreactjsreact-nativenode-modulescontentful

Import contentful in to react-native


I am extremely excited about using contentful for my project, but I can't get the JS library to work in a react-native project.

I get the following error: enter image description here

I have tried the following approaches:

import contentful from 'contentful'; 
// or
var contentful = require('contentful');

You can reproduce the bug by going to this repo and following the steps I have provided.

Help would be greatly appreciated.


Solution

  • I am maintaining the Contentful sdk. I've put together a simple example that shows how to use the SDK in React Native, you can check it here It is basically getting a list of items from one of our example spaces and display the names in a ListView.Check indes.ios.js. It looks like there is something wrong with the caching in your machine or so. Anyway I hope this helps.If you have more problems please feel free to create issues in our github page

    [UPDATE]

    you can now configure the axios instance used in the SDK to use a different adapter. You can pass that when calling createClient

    adapter: config => {
        config.adapter = null // this is important if it is passing to another axios instance
        // an http client combatible with React Native
        return fetch(config)
      }
    

    Best,

    Khaled