Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Component won't recognize it's being exported

I've encountered a very strange error. I feel that I've exported the Home component in a normal and conventional manner. Below, I've posted the .js files that I think are relevant in order to rectify this error. Despite this, In my iOS simulator, I'm still getting an error that says:

Element type is invalid: expected a string (for built-in components) or 
a class/function (for composite components) but got: undefined.  You 
likely forgot to export your component from the file it's defined in.

Check the render method of 'Home'.

Here's Home.js:

import React from 'react';
import Container from 'native-base';
import MapContainer from "../../../components/MapContainer/index";

class Home extends React.Component {

    componentDidMount() {
        this.props.setName();
    }

    render() {
        const region = {
            latitude: 3.146642,
            longitude: 101.695845,
            latitudeDelta: 0.8922,
            longitudeDelta: 0.0421
        }
        return(
            <Container>
                <MapContainer region={region}/>
            </Container>
        );
    }
}

export default Home;

Here's index.js:

import React from 'react';
import View from 'native-base';
import styles from './MapContainerStyles';
import * as MapView from "react-native-maps/lib/components/ProviderConstants";

const MapContainer = ({region}) => {
    return(
        <View style={styles.container}>
            <MapView
                provider={MapView.PROVIDER_GOOGLE}
                style={styles.map}
                region={region}
            >
            </MapView>
        </View>
    );
}

export default MapContainer;
like image 516
hop38 Avatar asked Feb 20 '26 17:02

hop38


1 Answers

The problem isn't your export of Home. We know that because Home's render is being called.

From the error, it looks like either Container or MapContainer isn't being imported correctly. I suspect it's that Container is a named export, so you need to use a named import:

import { Container } from 'native-base';

Update: Yup, here's an example from the NativeBase documentation:

import {Container, Content, Text} from 'native-base';
like image 85
T.J. Crowder Avatar answered Feb 22 '26 06:02

T.J. Crowder



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!