I am trying to use npm oxford-dictionary package in react-native, I installed "npm install oxford-dictioary" and run this file as "node app.js" on a terminal and works fine, However, when I tried to use in react native it doesn't work, can anyone help me what's is the problem. Is it possible to use this api at all with just react-native or I would have to build backend with nodejs ?
app.js
var Dictionary = require("oxford-dictionary");
var config = {
app_id : "-------",
app_key : "--------",
source_lang : "en"
};
var dict = new Dictionary(config);
var props = {
word: "stupendous",
};
var oxfordApi = {
getRovers(){
var lookup = dict.synonyms(props);
return fetch(lookup).then((res) => res.json());
}
}
import React from 'react';
import { StyleSheet, Text, View } from 'react-native';
//import oxfordApi from './oxfordApi';
import globals from 'node-libs-react-native/globals';
var Dictionary = require("oxford-dictionary");
var config = {
app_id : "-------",
app_key : "--------------------------",
source_lang : "en"
};
export default class App extends React.Component {
constructor(props) {
super(props);
this.state = {
rovers: []
}
}
componentWillMount() {
var dict = new Dictionary(config);
var lookup = dict.find("awesome");
lookup.then((res) => {
this.setState({
rovers: res.rovers
})
});
}
render() {
console.log("Rovers: ", this.state.rovers);
return (
<View style={styles.container}>
<Text>Hello wordl</Text>
</View>
);
}
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
});
The result When I run "run npm ios"
The package at "node_modules/oxford-dictionary/index.js" attempted to import the Node standard library module "https". It failed because React Native does not include the Node standard library. Read more at https://docs.expo.io/versions/latest/introduction/faq.html#can-i-use-nodejs-packages-with-expo