Dynamically Add featureLayer w/useEffect or otherwise in React

400
0
11-12-2021 01:11 PM
PeterBP
New Contributor

This may be a trivial oversight, nevertheless; Im trying to dynamically add a featureLayer and associated view.on event to a view that is created inside a useEffect hook. If I specify a second argument in the useEffect hook to listen for when to add the new featureLayer the entire map would be redrawn.

The scenario I am working with is:

  1. Client searches for address
  2. If their search query returns an incorrect result but brings them close to the correct location I would like to show/load a featureLayer with parcels so the client can make a selection on the map.

This show/load part is where I am having trouble. I can dynamically add what I want however when I do the entire map re-renderes because it is encapsulated inside the same useEffect hook as view. I would add them in an external function however the view and map are defined inside the useEffect hook so that doesn't seem to be an option either. Does anyone have any ideas?

0 Replies