Но вы говорите, что начальное состояние в нём не задаётся, а это не так.
class Example extends React.Component {
state = {
number: this.props.number,
};
}
class Example extends React.Component {
state = {};
static getDerivedStateFromProps(nextProps, prevState) {
if (prevState.number !== nextProps.number) {
return { number: nextProps.number };
}
return null;
}
}
function initMap() {
var e = {
lat: 40.714909,
lng: -73.751213
}
, t = new google.maps.Map(document.getElementById("map"), {
zoom: 16,
center: e
});
new google.maps.Marker({
position: e,
map: t
})
}
export initMap;
export { initMap } from './initMap;
getDerivedStateFromProps is invoked after a component is instantiated as well as when it receives new props.