I am following a tutorial from Udemy and got stuck here:
Yelp.js
import axios from "axios";
export default axios.create({
baseURL : 'https://api.yelp.com/v3/businesses',
headers : {
Authorization :
'Bearer ****************'
}
})
SearchScreen.js
const SearchScreen = () => {
const [term, setTerm] = useState('');
const [results, setResults] = useState([]);
const searchApi = async () => {
const response = await yelp.get('', {
params : {
term : term,
location: 'san jose'
}
});
setResults(response.data);
}
return (
<View style={styles.backgroundStyle}>
<SearchBar
term = {term}
onTermChange = {setTerm}
onTermSubmit = {searchApi} />
<Text>We have found {results.length} results</Text>
</View>
);
};
const styles = StyleSheet.create({
backgroundStyle : {
backgroundColor : '#FFFFFF',
flex: 1
}
})
export default SearchScreen
When searchApi is triggered I see this error in the console
[Unhandled promise rejection: Error: Network Error]
at node_modules/axios/lib/core/createError.js:15:17 in createError
at node_modules/axios/lib/adapters/xhr.js:114:22 in handleError
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:609:10 in setReadyState
at node_modules/react-native/Libraries/Network/XMLHttpRequest.js:396:6 in __didCompleteResponse
at node_modules/react-native/Libraries/vendor/emitter/_EventEmitter.js:135:10 in EventEmitter#emit
The same Api with the same Authorization key is working in Postman. Am I missing something here?