Component state leakage
See original GitHub issueI found an issue with the state of a component in preact, for example:
render(
<Parent>
<Child />
</Parent>,
document.body
)
class Parent extends Component {
componentDidMount() {
this.setState({FUBAR: true})
}
render() {
return this.props.children
}
}
class Child extends Component {
render() {
console.log(this.state) // <-- {FUBAR: true}, not undefined or {}
return null
}
}
As you can see, Parent
leaks its state to Child
because the default state object is reused across all components.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (10 by maintainers)
Top Results From Across the Web
Leakage (electronics) - Wikipedia
In electronics, leakage is the gradual transfer of electrical energy across a boundary normally viewed as insulating, such as the spontaneous discharge of...
Read more >State leaking between React sibling components
I'm having an issue with React passing state between sibling components when one of the siblings is deleted. In my program, each component ......
Read more >React State Update Memory Leak - Dev Genius
I've outlined one solution to a component trying to update its state once its been unmounted. This works if you're using lifecycle methods...
Read more >How to fix the React memory leak warning - DEV Community
Warning: Can't perform a React state update on an unmounted component. This is a no-op, but it indicates a memory leak in your...
Read more >Avoid Memory Leak With React SetState On An Unmounted ...
In this post I'll show some possible workarounds for avoiding memory leaks with data fetching.
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
working great 👍
Alright, let’s prioritize this then, it’s just too strange to leave open.