Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot useRef with functional components #8

Closed
kevinkdarling opened this issue Jun 20, 2021 · 3 comments
Closed

Cannot useRef with functional components #8

kevinkdarling opened this issue Jun 20, 2021 · 3 comments
Assignees
Labels
bug Something isn't working

Comments

@kevinkdarling
Copy link

First, thanks for the library. One of the examples shows a useRef to get a handle to a layer. However, when I tried that with DynamicLayer so that I could trigger an Identify task later, React of course complained that I could not use refs with such a component.

Am I missing something? Thanks for any help. If this is the wrong venue for such a question, please direct to the right spot. Thank you.

@slutske22 slutske22 self-assigned this Jun 20, 2021
@slutske22 slutske22 added the bug Something isn't working label Jun 20, 2021
@slutske22
Copy link
Owner

Wow I guess I never tested the refs before. You're right, this is a problem. I need to wrap the underlying EsriLeafletLayer in a forwardRef call to get this working, or make it a class component. I'll try to fix this as soon as I can. Currently, a crappy workaround is to do this:

import { EsriLeafletLayer } from "react-esri-leaflet";

const Map = () => {
  var dynamicMapLayerRef = React.useRef();

  return (
    <MapContainer ... >=
      <EsriLeafletLayer
        layerType="dynamicMapLayer"
        ref={dynamicMapLayerRef}
        url="your_layer_url"
      />
    </MapContainer>
  );
};

Here's a working example of that. Right this moment it seems that dynamic map layer url is not working on the arcgis side, but the ref to the layer is still working.

I'll get working on fixing this for real hopefully within the next few days.

@slutske22
Copy link
Owner

This is fixed now. Upgrade to 1.3.0 and you should be able to use refs normally as described in the docs. The examples also now have working examples of using refs (check out the <FeatureLayer /> component in either example folder). Let me know if you have any more issues with this.

@kevinkdarling
Copy link
Author

Just wanted to thank you very much for the fix! You saved our project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants