Switches between unfetch & node-fetch for client & server.
npm install @pure-model/isomorphic-unfetchsh
$ npm i isomorphic-unfetch
`
Then with a module bundler like rollup or webpack, use as you would anything else:
`javascript
// using ES6 modules
import fetch from 'isomorphic-unfetch'
// using CommonJS modules
const fetch = require('isomorphic-unfetch')
`
Usage
As a ponyfill:
`js
import fetch from 'isomorphic-unfetch'
fetch('/foo.json')
.then((r) => r.json())
.then((data) => {
console.log(data)
})
`
Globally, as a polyfill:
`js
import 'isomorphic-unfetch'
// "fetch" is now installed globally if it wasn't already available
fetch('/foo.json')
.then((r) => r.json())
.then((data) => {
console.log(data)
})
``