Skip to content
Advertisement

My app does not want to re-render, however the list in the context does

Short story: I am making my own GIS (geographic information system) and want to be able to upload JSON files with geographical data. I do not however want to save files in a database, just in a list. Furthermore I’m using Context to send data to the (leaflet) component. When I upload new JSONs to the layerList it gets updated but the component does not re-render. I have console logged the list after uploading files and the all get added.

The use of context is based off of DevEd’s guide on context from youtube https://www.youtube.com/watch?v=35lXWvCuM8o&t=1352s

Here is my code

Context:

JavaScript

Upload component:

JavaScript

Map:

JavaScript

Advertisement

Answer

EDIT: I pulled your repo and I think it’s solved now. Notice how the map.js component it’s logging the data from the updated .json file. Your map.js component should look like the following:

JavaScript

EDIT 2: I’m not sure what do you mean by the layers… but it’s showing the marker now with the static position you previously included in there. See below updated map.js:

JavaScript
User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement