Closed namnm closed 3 years ago
I'm thinking about for the v5 ! I'm actually checking to use fetch API that is not Node.js supported ... so do you have idea for simple API that can works in both environment (Node.js and Browser) without changes ??
@CICCIOSGAMINO Axios is the way https://github.com/axios/axios
I'm thinking at a function like this to init the right fetch .... with the use of node-fetch when in Node.js ...
async initFetch () {
const isBrowser = new Function('try {return this===window;}catch(e){ return false;}')
const isNode = new Function('try {return this===global;}catch(e){return false;}')
// tests if global scope is binded to window
if (isBrowser()) {
console.log('Running under browser')
}
if (isNode()) {
console.log('running under node.js')
nodeFetch = await import('node-fetch')
fetch = nodeFetch.default
}
}```
Yes this one can be a minimal set of changes, fetch is supported by default in browser and react-native.
Supported in v5.0.0-pre
Instead of using http/https package, we can use browser friendly package like fetch, axios, request... All those packages should work with Node and have ReactNative bindings.