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

Map loses WebGL context when setting data state in useEffect promise #1

Open
atomtay opened this issue Mar 16, 2021 · 0 comments
Open
Labels
bug Something isn't working

Comments

@atomtay
Copy link
Contributor

atomtay commented Mar 16, 2021

Layer components (such as MAPCMunicipality) need data in array form in order to correctly create the choropleth. Our usual way of doing this in React is as follows:

 const [data, setData] = useState();
  useEffect(() => {
    setData("!")
    d3.csv('/assets/some-file.csv')
      .then((response) => {
        setData(data);
      })
  }, []);

Where data is then passed to the layer. However, this causes the map to disappear and the following error to appear in the console (browser agnostic): WebGL context was lost (mapbox-gl.js 35). This doesn't occur when console.loging the response from .then, and it also doesn't occur when setting state outside the call to d3.csv (but inside useEffect).

@atomtay atomtay added the bug Something isn't working label Mar 16, 2021
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

1 participant