score:1
Accepted answer
you are directly mutating the state
like,
this.state.eventlist = requestresponse.data; //direct mutation
you never mutate state like this, because it is not the right way to change state and it will not re-render your component.
you must use setstate
to change your state, which will cause a re-render and your component will get data.
this.setstate({eventlist : requestresponse.data})
also make sure you are adding your child component when your data is ready,
{this.state.eventlist.length > 0 && <googleapiwrapper eventlist={this.state.eventlist} ></googleapiwrapper>}
score:0
main.js
import react from 'react';
import googlemapswrapper from './googlemapswrapper.js';
import { marker } from 'react-google-maps';
import markerclusterer from "react-google-/lib/components/addons/markerclusterer";
class demoapp extends react.component {
componentwillmount() {
this.setstate({ markers: [] })
}
componentdidmount() {
const url = [
// length issue
`https://gist.githubusercontent.com`,
`/farrrr/dfda7dd7fccfec5474d3`,
`/raw/758852bbc1979f6c4522ab4e92d1c92cba8fb0dc/data.json`
].join("")
fetch(url)
.then(res => res.json())
.then(data => {
this.setstate({ markers: data.photos });
});
}
render () {
return (
<googlemapswrapper
googlemapurl="https://maps.googleapis.com/maps/api/js?v=3.exp&libraries=geometry,drawing,places"
loadingelement={<div style={{ height: `100%` }} />}
containerelement={<div style={{ height: `400px` }} />}
mapelement={<div style={{ height: `100%` }}
defaultzoom={3}
defaultcenter={{ lat: 25.0391667, lng: 121.525 }}>
<markerclusterer
averagecenter
enableretinaicons
gridsize={60}>
{this.state.markers.map(marker => (
<marker
key={marker.photo_id}
position={{ lat: marker.latitude, lng: marker.longitude }}
/>
))}
</markerclusterer>
</googlemapswrapper>
);
}
}
googlemapswrapper.js
import react from 'react';
import { googlemap,withgooglemap,withscriptjs } from 'react-google-maps';
export default const googlemapswrapper = withscriptjs(withgooglemap(props => {
return <googlemap {...props} ref={props.onmapmounted}>{props.children}</googlemap>
}));
follow https://github.com/tomchentw/react-google-maps/issues/636
Source: stackoverflow.com
Related Query
- How fetch data by api and render child component with it - react google maps
- How to make React.js fetch data from api as state and pass this state data from its parent to child component
- How to Read image data from API and render in React Component
- How to fetch data from API and then pass it to another component in react after it is fully loaded?
- How to fetch data with axios for a placeid in Google maps and React?
- Why is my React component render called twice, once without data and then later with data, but too late exception?
- How to load child component with props on first render with React Hooks
- Loop through array and render multiple instances of a child component with that data with React?
- how to properly replace axios api with fetch api and map over the received data in nodeJS?
- How to fetch and display data from Express API to a React app?
- How do i render multiple props in a single component and then pass those props to a child component in React
- how to set an useEffect to fetch data from API at first render with eslint-react-hooks?
- How to iterate through a list of objects from api and render it to jsx page React functional component
- React Router v6 : How to render multiple component inside and outside a div with the same path
- How to make a react component that can be rendered with no data and later rendered with data?
- Jest with React - How do you render an entire component and test it?
- How to test child React component created in Render with React.createElement()
- How to fetch data from a custom React hook (API) with onClick and display it in a Div using TypeScript?
- In React How to pass object using history.push from a component to child component and read data
- In React How can I fetch data and render a single object in a states array without mapping the whole thing?
- How to load and display data with React from an API running on localhost
- How to fetch data and make a route with the same endpoint React
- Get new location and radius from Circle component in React Google Maps API
- How to render a child component within parent component using react and typescript?
- How to render the parent component in the child component using react and typescript?
- How to implement geolocation in a react app with Google Maps JS API instead of hard-coded location?
- Fetch data into React component and render it
- Passing int values from one react component to another with Google Maps API
- How to extract text input value and pass down that value down to a child component as a prop to use for fetching third part api data in React?
- How to fetch repeatedly and render updated api data in reactjs?
More Query from same tag
- React - how to make innerHtml inside the react router link to take the width of the parent element
- Dynamically calculate value in styling material-UI
- How to get parent component's name in React?
- Update value in object in nested array in React Firestore
- Pass boolean to expected react-element component props in material-ui list-item
- React JS printing data inside a nested map function in JSX
- How to refer components without typing the complete relative path?
- TypeScript error while accessing Proxy Object | Object[] in MobX
- ReactJS ReactDOM Render for Separate Pages
- How to change style of react-select selected options?
- how to re-render after getting axios response in jest test
- how to convert date of the form 'xxth mar yyyx' in 'dd/mm/yy' format?
- How do I render a single Item fetched from the API ReactJS
- Redux: altering different parts of the initial state in Reducer according to Actions
- react-hot-loader: React.createElement: type is invalid -- expected a string error updating the screen
- How can I render Reference fields from Contentful in React?
- Hide Element Dynamically in ReactJS
- REACT : getting error while re-rendering components using setState hook
- Antd Forms, get values from custom component?
- react.js rendering dynamic images not working
- Function works but won't return HTML?
- Objects are not valid as a React child (found: TypeError: NetworkError when attempting to fetch resource.)
- This is a question about setting up routing routes
- ReactJS setState with multidimensional object and dynamic key
- redirect all the routes to a page
- Webview causing react-native app to crash on navigation
- Bootstrap React Jumbotron Background Image
- Passing environment variables in dockerfile
- Bootstrap V5 Modal not hiding via Javascript Unless Window Method
- React js- bootstrap Value not showing on Tab change