fetch method is not defined using ES6 fetch in React

后端 未结 2 1614
独厮守ぢ
独厮守ぢ 2021-02-13 17:13

I have a trouble with fetch functions in my first react js app.

This is the structure of my project:

hello-world
  -- app
     -- components
       -- ma         


        
相关标签:
2条回答
  • 2021-02-13 18:01

    It's an exported default, so...

    import fetch from 'isomorphic-fetch'
    
    0 讨论(0)
  • 2021-02-13 18:06

    Adding a polyfill for this is the correct approach. Looking at one of my latest projects you just need to do the following imports;

    import promise from 'es6-promise';
    import 'isomorphic-fetch';
    
    promise.polyfill();
    

    It looks like you've not quite got the es6-promise import correct which requires the .polyfill() method be called. I'd recommend putting these in the entry point of the application as you should only need to import them once.

    I'd also recommend you include the babel polyfill;

    import 'babel-polyfill';
    
    0 讨论(0)
提交回复
热议问题