Google API: Invariant Violation: View config getter callback for component `div` must be a function (received `undefined`)

Viewed 81

I'm making simple google api app by TypeScript via expo. Here is my script. It may shows simple map view.

import React, { useEffect, useState } from "react";
import GoogleMapReact from "google-map-react";
import {
  View
} from 'react-native';

interface MapProps {
  center: {
    lat: number;
    lng: number;
  };
  zoom: number;
}


const initialMapProps: MapProps = {
  center: {
    lat: 35.39,
    lng: 139.44,
  },
  zoom: 18,
};

const API_KEY = "MyGoogleApiToken";

export default function Apps() {
  const [mapProps, setMapProps] = useState<MapProps>(initialMapProps);
  return (
    <View style={{ width: "100vw", height: "100vh" }}>
      <GoogleMapReact
        bootstrapURLKeys={{ key: API_KEY }}
        center={mapProps.center}
        zoom={mapProps.zoom}
      />
    </View>
  );
};

But I received error below:

Invariant Violation: View config getter callback for component `div` must be a function (received `undefined`). Make sure to start component names with a capital letter.

This error is located at:
    in div (created by t)
    in t (created by t)
    in div (created by t)
    in t (created by Apps)
    in RCTView (created by View)
    in View (created by Apps)
    in Apps (created by ExpoRoot)
    in ExpoRoot
    in RCTView (created by View)
    in View (created by AppContainer)
    in DevAppContainer (created by AppContainer)
    in RCTView (created by View)
    in View (created by AppContainer)
    in AppContainer
    in main(RootComponent)

I tried

  • update react 17 to 18
  • uninstall and install again node
  • uninstall and install expo-cli
  • use javascript instead of typescript
  • add resolutions, overwrites columns to package.json

None of them worked. If I only put Texts, It works. So It definitely Google API doesn't work. But I can't understand what's wrong.Anybody have any ideas?

Current package.json is as follows.

{
  "name": "test-app",
  "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",
    "eject": "expo eject"
  },
  "dependencies": {
    "expo": "~45.0.0",
    "expo-status-bar": "~1.3.0",
    "google-map-react": "^2.1.10",
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "react-native": "0.68.2",
    "react-native-web": "0.17.7",
    "react-native-webview": "11.18.1",
    "uuid": "^8.3.2"
  },
  "devDependencies": {
    "@babel/core": "^7.12.9",
    "@types/google-map-react": "^2.1.7",
    "@types/react": "~17.0.21",
    "@types/react-native": "~0.66.13",
    "typescript": "~4.3.5"
  },
  "resolutions": {
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "@types/react": "^17.0.38",
    "@types/react-native": "~0.66.13"
  },
  "overwrites": {
    "react": "17.0.2",
    "react-dom": "17.0.2",
    "@types/react": "^17.0.38",
    "@types/react-native": "~0.66.13"
  },
  "private": true
}

1 Answers

Any React libraries that depend on UI will not work in React Native. The building blocks are all different. There are no web components (div, etc); there are native UI components (View, Text). There's no CSS, there are StyleSheets.

If you're looking for UI in a library, you'll need to find one made for React Native, or write your own based on the React library you found.

Unfortunately if you search for the difference between React and React Native the answers you'll get are typically very general. This thread has some of the key differences in writing UI between the two: https://www.reddit.com/r/reactjs/comments/h8tmsj/how_big_is_the_jump_from_react_to_react_native/

Related