I am trying to run my Expo App on the iPhone/Android devices, but I receive
"undefined is not a function (near'...posts.map...')"
But the application runs on iOS emulator...It does show the error on the Android emulator. I'm fairly new to React Native and I'm trying to figure out why it's not returning the objects for my iPhone (physical) and Android Emulator.
The full error is below and the code that I wrote will follow it. How can I fix this TypeError issue and correctly display the results on my iPhone/Android Emulator?
Full Error:
TypeError: undefined is not a function
(near'...posts.map')
This error is located at:
in Home (created by
Context.Consumer)
in Route (at App.js:21)
in Switch (at App.js.30)
in RCTSafeAreaView (at SafeAreaView.js:55)
in SafeAreaView (at App.js:19)
in App (at App.js:35)
in Router (created by Memory Router)
....
My React Native Code:
import React, {useState, useEffect} from 'react';
import Axios from 'axios'
import {ScrollView} from 'react-native';
import PhotoPost from '../components/PhotoPost';
import ErrorBoundary from 'react-native-error-boundary'
const Home = () => {
const [posts, setPosts] = useState([]);
useEffect( () => {
Axios.get('http://127.0.0.1:3000/image_post/index')
.then(res => {
setPosts(res.data)
}).catch(e => setPosts(e.message))
}, []);
return (
<ScrollView>
<ErrorBoundary>
{posts.map((posts, index) => {
return(
<PhotoPost key={index} post={post} />
)
})}
</ErrorBoundary>
</ScrollView>
)
}
export default Home