Last active
June 25, 2020 12:41
-
-
Save velotiotech/b8bcd2d3df0261d71c8d56c3b6a7dd2a to your computer and use it in GitHub Desktop.
Cleaner Efficient Code with Hooks and Functional Programming - Huge Components issue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Class component | |
import React from "react"; | |
export default class LazyLoader extends React.Component { | |
constructor(props) { | |
super(props); | |
this.state = { data: [] }; | |
} | |
loadMore = () => { | |
// Load More Data | |
console.log("loading data"); | |
}; | |
handleScroll = () => { | |
if (!this.props.isLoading && this.props.isCompleted) { | |
this.loadMore(); | |
} | |
}; | |
componentDidMount() { | |
this.loadMore(); | |
document.addEventListener("scroll", this.handleScroll, false); | |
// more subscribers and event listeners | |
} | |
componentDidUpdate() { | |
// | |
} | |
componentWillUnmount() { | |
document.removeEventListener("scroll", this.handleScroll, false); | |
// unsubscribe and remove listeners | |
} | |
render() { | |
return <div>{this.state.data}</div>; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment