nebula.gl
nebula.gl copied to clipboard
misuse of this.setState in addFeatures and deleteFeatures
Describe the bug
My application is performing deleteFeatures
with an immediate addFeatures
operation.
deleteFeatures
is using this.setState(<new value>)
, which is "async" by nature, which doesn't guarantee action will happen right now.
addFeatures
is doing the same thing.
Actual Result
I end up with more than 1 features on the map, because the delete never "happens".
Expected Result
Only 1 feature should be on map.
Reproduce Steps
Version: 0.21.0 A simple code can demonstrate the issue:
editorRef.current.addFeatures(feature1) // start with a single feature
// delete the first feature (the only one) and add another feature
editorRef.current.deleteFeatures(0)
editorRef.current.addFeatures(feature2)
Note: this might be solved if using setState
with function argument (this.setState(prevState => ....)
).
Another option is to allow users to pass a callback to be notified on onDelete
, onAdd
, etc...