Skip to content

Commit

Permalink
Avoid wrapping via contextType
Browse files Browse the repository at this point in the history
  • Loading branch information
herecydev committed Feb 20, 2020
1 parent f60e994 commit 62625b9
Showing 1 changed file with 6 additions and 11 deletions.
17 changes: 6 additions & 11 deletions packages/gatsby-react-router-scroll/src/ScrollContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ScrollContainer extends React.Component {
}

componentDidMount() {
this.props.context.registerElement(
this.context.registerElement(
this.props.scrollKey,
ReactDOM.findDOMNode(this), // eslint-disable-line react/no-find-dom-node
this.shouldUpdateScroll
Expand Down Expand Up @@ -50,7 +50,7 @@ class ScrollContainer extends React.Component {
}

componentWillUnmount() {
this.props.context.unregisterElement(this.scrollKey)
this.context.unregisterElement(this.scrollKey)
}

shouldUpdateScroll = (prevRouterProps, routerProps) => {
Expand All @@ -61,7 +61,7 @@ class ScrollContainer extends React.Component {

// Hack to allow accessing scrollBehavior._stateStorage.
return shouldUpdateScroll.call(
this.props.context.scrollBehavior,
this.context.scrollBehavior,
prevRouterProps,
routerProps
)
Expand All @@ -72,12 +72,7 @@ class ScrollContainer extends React.Component {
}
}

const ScrollContainerConsumer = props => (
<ScrollBehaviorContext.Consumer>
{context => <ScrollContainer {...props} context={context} />}
</ScrollBehaviorContext.Consumer>
)
ScrollContainer.propTypes = propTypes
ScrollContainer.contextType = ScrollBehaviorContext

ScrollContainerConsumer.propTypes = propTypes

export default ScrollContainerConsumer
export default ScrollContainer

0 comments on commit 62625b9

Please sign in to comment.