インポート間違いによるElement type is invalid: expected a stringエラーの解決方法について

react-native-mapsにマーカーを追加してビルドしたところ以下のエラーが発生。

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,
or you might have mixed up default and named imports.

原因は

import { MapView, Marker} from 'react-native-maps';

と定義していたため

正しくはこう

import MapView, { Marker} from 'react-native-maps';

単純にインポート方法が違っていたためでした。

MarkerやImageといった小道具はカッコで囲み、メインライブラリであるMapViewのみ

外に出すという概念でしょうか。

確かreactをインポートするときも

import React, { useState, useEffect } from 'react';

だったのでこの法則は合っているかもしれない。

>株式会社シーポイントラボ

株式会社シーポイントラボ

TEL:053-543-9889
営業時間:9:00~18:00(月〜金)
住所:〒432-8003
   静岡県浜松市中央区和地山3-1-7
   浜松イノベーションキューブ 315
※ご来社の際はインターホンで「316」をお呼びください

CTR IMG