Lifecycle metodlar huklar yordamida, yoki nega useEffect metodidan foydalanishni boshlashingiz kerak.

useEffect()

useEffect(()=>{
//code
}, [dep1, dep2])
useEffect(()=>{
fetchArticle({page: page, limit: 10, search: search})
}, [search, page])

componentDidMount()

componentDidMount(){
fetchArticles({page: 1, limit: 10});
}
useEffect(() => {
fetchArticles({ page: 1, limit: 10 });
}, []);

componentDidUpdate()

componentDidUpdate(){
renderCount++;
}
useEffect(()=>{
renderCount++;
})

componentWillUnmount()

componentWillUnmount(){
unsubscribeAuth();
}
Ushbu metodimizni useEffect orqali qilish ham juda oson, shunchaki istalgan ko’rinishdagi useEffect metodimizga beradigan funksiyamizdan yangi bir funksiya qaytarish kerak, va ushbu funksiyamiz componentDidUpdate metodi o’rniga o’tadi. useEffect(() => {
return () => {
//sizning kodingiz
unsubscribeAuth();
};
}, []);

Boshqa lifecycle metodlari

--

--

React dev.

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store