错误警告:React.createElement:类型无效--应为字符串(对于内置组件)或类/函数(对于复合组件)

a9wyjsp7  于 2023-03-24  发布在  React
关注(0)|答案(1)|浏览(103)

我试图测试Geojson库,但我被这个错误卡住了。
我下面发送我的app.jspackage.json代码是从this repository复制。

应用程序js

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

const myPlace = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {},
      geometry: {
        type: 'Point',
        coordinates: [64.165329, 48.844287],
      }
    }
  ]
};

const Map = props => (
  <MapView>
    <Geojson 
      geojson={myPlace} 
      strokeColor="red"
      fillColor="green"
      strokeWidth={2}
    />
  </MapView>
);

包.json

{
  "name": "geojsonvalidation",
  "version": "1.0.0",
  "main": "node_modules/expo/AppEntry.js",
  "scripts": {
    "start": "expo start",
    "android": "expo start --android",
    "ios": "expo start --ios",
    "web": "expo start --web"
  },
  "dependencies": {
    "expo": "~48.0.6",
    "expo-app-loading": "^2.1.1",
    "expo-asset": "^8.9.1",
    "expo-font": "^11.1.1",
    "expo-status-bar": "~1.4.4",
    "geojson": "^0.5.0",
    "react": "18.2.0",
    "react-native": "0.71.3",
    "react-native-maps": "1.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.20.0"
  },
  "private": true
}

我只是在验证未来可能的解决方案。

xe55xuns

xe55xuns1#

考虑导出您的主组件:

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

const myPlace = {
  type: 'FeatureCollection',
  features: [
    {
      type: 'Feature',
      properties: {},
      geometry: {
        type: 'Point',
        coordinates: [64.165329, 48.844287],
      }
    }
  ]
};

const Map = props => (
  <MapView>
    <Geojson 
      geojson={myPlace} 
      strokeColor="red"
      fillColor="green"
      strokeWidth={2}
    />
  </MapView>
);

export default Map; // <——- add this line

相关问题