",
13 | "license": "ISC",
14 | "peerDependencies": {
15 | "prop-types": "^15.5.7",
16 | "react": "^15.x || ^16.x",
17 | "react-dom": "^15.x || ^16.x",
18 | "react-leaflet": "^2.0.1"
19 | },
20 | "repository": "https://github.com/masotime/react-leaflet-universal",
21 | "devDependencies": {
22 | "@babel/cli": "^7.0.0",
23 | "@babel/core": "^7.0.0",
24 | "@babel/plugin-proposal-class-properties": "^7.0.0",
25 | "@babel/plugin-proposal-decorators": "^7.0.0",
26 | "@babel/plugin-proposal-do-expressions": "^7.0.0",
27 | "@babel/plugin-proposal-export-default-from": "^7.0.0",
28 | "@babel/plugin-proposal-export-namespace-from": "^7.0.0",
29 | "@babel/plugin-proposal-function-bind": "^7.0.0",
30 | "@babel/plugin-proposal-function-sent": "^7.0.0",
31 | "@babel/plugin-proposal-json-strings": "^7.0.0",
32 | "@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
33 | "@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
34 | "@babel/plugin-proposal-numeric-separator": "^7.0.0",
35 | "@babel/plugin-proposal-optional-chaining": "^7.0.0",
36 | "@babel/plugin-proposal-pipeline-operator": "^7.0.0",
37 | "@babel/plugin-proposal-throw-expressions": "^7.0.0",
38 | "@babel/plugin-syntax-dynamic-import": "^7.0.0",
39 | "@babel/plugin-syntax-import-meta": "^7.0.0",
40 | "@babel/plugin-transform-runtime": "^7.0.0",
41 | "@babel/preset-env": "^7.0.0",
42 | "@babel/preset-react": "^7.0.0",
43 | "@babel/runtime-corejs2": "^7.0.0",
44 | "babel-eslint": "^9.0.0",
45 | "babel-plugin-add-module-exports": "^1.0.2",
46 | "babel-plugin-module-resolver": "^4.0.0",
47 | "eslint": "^5.16.0",
48 | "eslint-import-resolver-babel-module": "^5.1.0",
49 | "eslint-plugin-import": "^2.17.1",
50 | "eslint-plugin-react": "^7.17.0",
51 | "leaflet": "^1.3.4",
52 | "react": "^15.x || ^16.x",
53 | "react-dom": "^15.x || ^16.x",
54 | "react-leaflet": "^2.0.1"
55 | }
56 | }
57 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # react-leaflet-universal
2 |
3 | Thin wrapper around [react-leaflet][react-leaflet-url] that is designed to make it easier to implement the module in universal applications. Leaflet was not designed with the server in mind, making it very difficult to work with for server-side rendering.
4 |
5 | To sidestep this issue, we simply don't render server side. This module wraps all of `react-leaflet`'s components in a Wrapper class that only renders when the component is mounted - which only happens client-side.
6 |
7 | ## usage
8 |
9 | Just use it as you normally would use `react-leaflet`. e.g. Instead of
10 |
11 | ```
12 | import { Map } from 'react-leaflet';
13 | ```
14 |
15 | write
16 | ```
17 | import { Map } from 'react-leaflet-universal';
18 | ```
19 |
20 | To forward reference, pass to `leafletRef`:
21 |
22 | ```
23 |
26 | ```
27 |
28 | If you do not provide `leafletRef`, wrappers will instead create their own ref and set the property `leafletElement` on the instance when it becomes available, so setting a `ref` prop will still work, however note that since this only occurs late in the render cycle, `leafletElement` may still be undefined when attempting to access it from the `ref`, so it is recommended to check that `ref.leafletElement` exists before attempting to invoke properties or methods on it.
29 |
30 | ## Troubleshooting custom `react-leaflet` components / render prop support
31 |
32 | Some components, such as [react-leaflet-markercluster][markercluster-url], make use of `componentWillMount` and so cannot be used directly.
33 |
34 | To mitigate this, you can now use a function [render prop][render-prop-url] instead of normal children for a component. Thus, instead of e.g.
35 |
36 | ```
37 |
40 | ```
41 |
42 | this will also work
43 |
44 | ```
45 |
50 | ```
51 |
52 | So in the case of `react-leaflet-markercluster`, you can write something similar to:
53 |
54 | ```
55 |
75 | ```
76 |
77 | (contrast with the [example on the react-leaflet-markercluster website][markercluster-example-url])
78 |
79 | Note: If you use React 16.2+, [you can also make use of `` or simply `<>>`][react-16-fragment-example] instead of the wrapping `` in the example above.
80 |
81 | [react-leaflet-url]: https://www.npmjs.com/package/react-leaflet
82 | [markercluster-url]: https://www.npmjs.com/package/react-leaflet-markercluster
83 | [markercluster-example-url]: https://github.com/YUzhva/react-leaflet-markercluster#getting-started
84 | [render-prop-url]: https://cdb.reacttraining.com/use-a-render-prop-50de598f11ce
85 | [react-16-fragment-example]: https://reactjs.org/blog/2017/11/28/react-v16.2.0-fragment-support.html
86 |
--------------------------------------------------------------------------------