ReactJS - setState causes viewer to re-render every time
See original GitHub issueWhen using Resium with ReactJS and adding an ImageLayer
, it is causing the viewer to refresh every time any setState
is called. How can I use setState
to update certain parts of the page without re-rendering the map?
Example below and screenshot of the issue
` class LiveMap extends React.PureComponent { viewerRef = React.createRef(); state = { name: “test” };
handleSelectedEntityChanged = (event) => {
console.log("selected: " + event);
this.setState({
...this.state,
name: this.state.name === "test" ? "testt" : "test"
});
};
render() {
const defaultImageryProvider = new UrlTemplateImageryProvider({
url : "https://cartodb-basemaps-{s}.global.ssl.fastly.net/dark_all/{z}/{x}/{y}.png"
});
return (
<Viewer
full
ref={this.viewerRef}
onSelectedEntityChange={this.handleSelectedEntityChanged}>
<ImageryLayer imageryProvider={defaultImageryProvider} />
<Entity
name={this.state.name}
position={Cartesian3.fromDegrees(61, 130, 100)}
point={{ pixelSize: 10 }} />
</Viewer>
);
}
}; `
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:6 (3 by maintainers)
Top Results From Across the Web
ReactJS - Does render get called any time "setState" is called?
React doesn't compare state data. When setState is called, it marks the component as dirty (which means it needs to be re-rendered). The ......
Read more >setState causes viewer to re-render every time · Issue #372 ...
When using Resium with ReactJS and adding an ImageLayer, it is causing the viewer to refresh every time any setState is called. How...
Read more >React doesn't always trigger a re-render on setState
For new React developers, it is common to think that setState will trigger a re-render. But this is not always the case. If...
Read more >When does React re-render components? - Felix Gerschau
The reasoning behind this is that React re-renders a component if its state changes, but it doesn't re-render the props if they don't...
Read more >Just Say No to Excessive Re-Rendering in React - GrapeCity
Re-renders occur when a component's state or prop changes. When neither changes, no re-render occurs. Just like the initial render, a re-render ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
imageProvider
prop ofImageryLayer
component is read-only and is not changeable becauseImageProvider
ofImageryLayer
of Cesium API is also read-only.If the imageProvider is static, you can use outside const variable or
useMemo
hook as described in this page.If you want to change the imageProvider dynamically, you cannot avoid regenerating the ImageryLayer. If you want to completely suppress warnings, key props can be used:
We are also considering suppressing the warnings. Either way, please understand that the imageProvider is read-only.
I think I have the same issue. When I update variable in parent that holds Entities as children, they all get redrawn