effrenus / yandex-map-react

70 stars 22 forks source link

server-side rendering #25

Closed maxneh closed 7 years ago

maxneh commented 7 years ago

When i use this component in isomorfic app and server-side rendering , then i have error:

node_modules\yandex-map-react\lib\api.js:21
        this.api = window.ymaps ? window.ymaps : null;
                   ^
ReferenceError: window is not defined
maxneh commented 7 years ago

I find solution for myself


import React from 'react';
import {canUseDOM} from 'fbjs/lib/ExecutionEnvironment';

class Maps extends React.Component{

  render() {
    if (canUseDOM) {
      const {Map, Marker} = require("yandex-map-react");
      return (<Map center={[55.754734, 37.583314]} zoom={10}>
        <Marker lat={55.754734} lon={37.583314}/>
        <Marker lat={55.783} lon={37.604545}/>
      </Map>)
    }
    else {
      return null
    }
  }
}
export default Maps;
effrenus commented 7 years ago

Think I fix error with window host object. Try without polyfill, pls.

maxneh commented 7 years ago

@effrenus I check updated package - no errors. thanks for quick fix