-
Notifications
You must be signed in to change notification settings - Fork 190
Closed
Description
The handleChange callback always calls setState regardless of whether or not the value for state.inView will change. This forces a React Tree Reconciliation for each observed component when the tree is mounted (IO calls the callback once for each observed component).
I think an optimization could be made to https://github.com/thebuilder/react-intersection-observer/blob/master/src/InView.tsx#L96:
handleChange = (inView: boolean, entry: IntersectionObserverEntry) => {
if (inView !== this.state.inView || inView) {
this.setState({ inView, entry })
}
if (this.props.onChange) {
this.props.onChange(inView, entry)
}
}
This would allow the child to receive a new value for entry when in view (where it counts), but would prevent the re-render/reconciliation that happens at the very beginning.
What do you think? Am I missing some context here?
Metadata
Metadata
Assignees
Labels
No labels