Error: React map is failing to display correctly

I'm struggling to display my Google Maps on the screen. Even after referring to this question, I still can't solve my issue.

Here is what I have:

import React from 'react'
import GoogleMap from 'google-map-react';
import withStyles from 'isomorphic-style-loader/lib/withStyles'
import s from './CarMap.css'

class MoobieMap extends React.Component {

    constructor(props){
        super(props)
    }

    render() {
        return (
            <div className={s.map}>
            <GoogleMap apiKey={API_KEY} center={{lat: -23.5925282, long: -46.6891377}} zoom={3}/>
            </div>
        )
    }
}

export default withStyles(s)(MoobieMap)

Additionally:

import React from 'react'
import Layout from '../../components/Layout'
import MoobieMap from './CarMap'

const title = 'Mapa de carros'

export default {

  path: '/car-map',

  async action() {
    return {
      title,
      chunk: 'component',
      component: <Layout title={title}><MoobieMap /></Layout>,
    }
  },

}

As for the CSS:

.map {
    width: 100%;
    height: 400px;
}

In addition to using the React starter kit, my DOM structure resembles this:https://i.sstatic.net/bYOcL.png

No JavaScript errors appear in my console either.

What could I be overlooking here? Thanks!!!

UPDATE: https://i.sstatic.net/a9TBm.png

Answer №1

Make sure to include only the CSS without specifying names like this:

import React from 'react'
import GoogleMap from 'google-map-react';
import withStyles from 'isomorphic-style-loader/lib/withStyles'
import './CarMap.css'

class MoobieMap extends React.Component {

    constructor(props){
        super(props)
    }

    render() {
        return (
            <div>
            <GoogleMap apiKey={API_KEY} center={{lat: -23.5925282, long: -46.6891377}} zoom={3} className="map"/>
            </div>
        )
    }
}

export default withStyles(s)(MoobieMap)

What does the (s) mean between the connection of MoobieMap and withstyles?

I hope this explanation helps, and make sure that your .map class has width and height declared...

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to design the unique curly arrow/tail for a chat bubble in a React Native project?

Being new to react-native, I decided to create a chat bubble by first attempting it on a browser and then trying to replicate it in react-native. The challenge I'm facing is replicating the arrow in react-native. Do you have any ideas or suggestions? ...

If I do not utilize v-model within computed, then computed will not provide a value

I'm fairly new to coding in JS and Vue.js. I've been attempting to create a dynamic search input feature that filters an array of objects fetched from my API based on user input. The strange issue I'm coming across is that the computed metho ...

Tips for efficiently importing a file or folder that is valuable but not currently in use

I'm struggling to find any information about this particular case online. Perhaps someone here might have some insight. I keep getting a warning message saying 'FournisseursDb' is defined but never used no-unused-vars when I try to import t ...

Using scope in ng-style to manipulate a portion of a CSS property value in Angular

I've been attempting to add a border using ng-style, but I'm struggling to figure out how to concatenate the value from the scope variable. None of the methods below seem to be working for me: <div ng-style="{'border-top' :'1p ...

Attempting to establish a cookie from the server end, however, it is not being successfully set on my client

Attempting to set a cookie on the client browser from the server side using Node.js and Express. When signing up, the cookie is properly sent in the response object but not being set on the client browser. Additionally, when trying to access a protected AP ...

Unable to successfully rename an uploaded file utilizing Multer in the Express.js environment

While working on uploading a file from an HTML form using Express.js and Multer, I have successfully saved the file to a specific location (a folder named uploads). However, I am looking to rename the file during the upload process because Multer assigns ...

Shift the input's focus after altering the select option using Element UI and Vue.js

When choosing a product from the selection menu, be sure to click on the desired product and then focus on the quantity input field. If you are having trouble using the ref attribute, check out the following link for more information: <el-select ...

Encountering a hiccup while trying to run 'npm install' on WSL2

Whenever I try to run npm install in my project, this error keeps popping up. Oddly enough, I've never encountered this issue on any other machine before. However, this is my first attempt on WSL2 Ubuntu and it's giving me trouble. Here is the er ...

Creating a thumbnail with a close button using an image

My code is available at the following link: https://codepen.io/manuchadha/pen/PBKYBJ In this form I have created, I am trying to implement an image upload feature using a file input. The goal is to display a thumbnail of the selected image below the file ...

Establish a connection to AWS by utilizing MQTT.js

Looking to create a web page that connects to an AWS server? While python-Paho-mqtt allows for the use of tls_set to add security certificates and more, how can we achieve the same with MQTT.js? And if unable to do so, what are the steps to run python-PAHO ...

A step-by-step guide to implementing Inline Linear Gradient in Nuxt/Vue

How can I create a linear gradient overlay on top of my inline background image? I attempted to add a CSS style but the class seems to be positioned beneath the image. <div class="header__bkgd" v-bind:style="{'background-image': 'url(&ap ...

What is the best way to incorporate JavaScript code as React syntax?

For my project, I am using the OpenLayers API Map. I'm unsure of the correct way to incorporate JavaScript code in React or vice versa. Here is an answer on how to use markers in the map, but I am struggling to implement it in my current code since I ...

Sending a group of checkboxes via Ajax using AngularJS

I am facing a challenge with making an ajax GET request where I need to submit an array of checkboxes, all with the same name. The checkboxes are defined as follows: type[] = new type[] = used type[] = refurbished The purpose of this is to fulfill the r ...

What is the most effective way to view all globally installed npm packages on my device?

While it's easy to check local dependencies in the package.json file, I'm curious about how one can identify the global packages that are currently installed on a Windows machine using npm. ...

creating unique styles for your Ionic app with Angular using JSON

Having trouble changing the item color. Does anyone know why my CSS isn't working, or if I'm missing something? <ion-view title="Add order to a table"> <ion-content class="has-header has-subheader"> <ion-list> ...

Update the display of the mouse pointer

I use CSS to set a custom cursor image: #scroll_up{ display: block; position: absolute; width: 960px; height: 300px; cursor: url(../imgs/cursor_up.png), auto; } The above style is assigned to a div element so that the cursor appea ...

The Element Ui component fails to update when the prop of the Vue component changes

In my project, I have a parent component and several child components which all make use of the same prop. This prop is an array of keys that are used for a dropdown menu in element.js. Initially, when the children render for the first time, they do not co ...

When using jQuery 1.7 or higher, the on(click..) function may not function correctly on dynamically added <li> elements

Currently, I am working on a dialogue that contains an unordered list with various suggestions. The HTML code for this section is as follows: <ul id="suggestions0"> <li id="suggestion0-0" class="suggestion">BLO</li> <li id="su ...

Validating an item within an enumeration

In my enum, I store various UI element values organized as follows: const uiElementAttributes = { 1: { id: 1, color: 'red', icon: 'icon-something.png' }, 2: { id: 2, color: 'yellow', ...

CodeIgniter's ajax integration with JSON encoding is failing to function properly

I'm in need of some assistance. The issue I'm facing is that the code seems to be unresponsive, and I can't seem to pinpoint the problem. Below is the code snippet from my View: <div id="ysfhkm_slc_country"> <select name="ysfh ...