React JS में अनंत स्क्रोलिंग जोड़ें 🔥

Posted by


ReactJS में अनगिनत स्क्रोलिंग जोड़ने के लिए निम्नलिखित ट्यूटोरियल में विस्तृत तरीके से बताया गया है।

कदम 1: पैकेज का इंस्टालेशन
पहला कदम है react-infinite-scroll-component पैकेज को इंस्टॉल करना होगा। आप निम्नलिखित कमांड का उपयोग करके इस पैकेज को अपने रिएक्ट प्रोजेक्ट में इंस्टॉल कर सकते हैं:

npm install react-infinite-scroll-component

कदम 2: React Component में InfiniteScroll का इम्पोर्ट
अब आपको अपने रिएक्ट कंपोनेंट में react-infinite-scroll-component पैकेज को इम्पोर्ट करना होगा। निम्नलिखित लाइन को अपने कंपोनेंट में जोड़े:

import InfiniteScroll from 'react-infinite-scroll-component';

कदम 3: State और Data का सेटअप
अब आपको एक स्टेट वैरिएबल बनानी होगी जो आपके डेटा को स्टोर करेगी। उदाहरण के लिए, आपका कंपोनेंट निम्नलिखित रूप में देख सकता है:

const [items, setItems] = useState([]);
const [hasMore, setHasMore] = useState(true);

कदम 4: InfiniteScroll कंपोनेंट का उपयोग
अब आपको InfiniteScroll कंपोनेंट का उपयोग करना होगा अपने डेटा को लोड करने के लिए। निम्नलिखित कोड की सहायता से आप इसे कर सकते हैं:

<InfiniteScroll
    dataLength={items.length}
    next={fetchData}
    hasMore={hasMore}
    loader={<h4>Loading...</h4>}
>
    {items.map((item, index) => (
        <div key={index}>{item}</div>
    ))}
</InfiniteScroll>

कदम 5: fetchData Function का बनाना
अब आपको एक fetchData फंक्शन बनानी होगी जो नए डेटा को लोड करेगी। यहाँ एक उदाहरण दिया गया है:

const fetchData = () => {
    // अपने डेटा को लोड करने के लिए यहाँ API का कॉल करें और फिर स्टेट को अपडेट करें
}

इस तरह से, आप अपने रिएक्ट एप्लिकेशन में अनगिनत स्क्रोलिंग को जोड़ सकते हैं। यह ट्यूटोरियल आपको पूर्ण जानकारी प्रदान करेगा कि कैसे आप अपने परियोजना में इस फीचर को शामिल कर सकते हैं।

धन्यवाद।

0 0 votes
Article Rating

Leave a Reply

50 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
@ThapaTechnical
1 hour ago

👉 Free Source Code Link: https://www.thapatechnical.com/2023/01/infinite-scrolling-in-react-js.html

😊 Become Member, get access to perks, free Source code, & more..

https://www.youtube.com/channel/UCwfaAHy4zQUb2APNOGXUCCA/join

😍 Check my Instagram to Connect with me: https://www.instagram.com/thapatechnical

👩‍💻 Discord Server Link for Programmer to Hangout: https://discord.gg/MdScmCsua6

✌ Website Link: https://www.thapatechnical.com

@vishalkyadav3805
1 hour ago

bro make a tutorial for creating a website like yours.

@RameshJobUpdates
1 hour ago

Excellent Explanation❤

@preetiipriya
1 hour ago

Mera initial data 1-9 double render ho rha hai

@FUNABRAR
1 hour ago

❤❤❤

@ashispyne123
1 hour ago

after last record, if I scroll up and down, its again loading the function, will it be normal to load every time where we reached the last data?

@suball
1 hour ago

Bro how can we write limite &page api with object array data

@rrttingre3222
1 hour ago

source code is not working they are showing index.js file is not present

@jokerwatch8010
1 hour ago

bhai aap likhate ho tab fire dikhati hai o edting hai ya koi theme hai vs code ki

@shivamaggarwal2023
1 hour ago

Thank you Bhai ❤

@musicworld1717
1 hour ago

finally someone teaches indepth thanks …love you bro

@AzadChauhan-l1x
1 hour ago

Tell me the name of the song at the end of the video ? Its Nepali song ?

@AzadChauhan-l1x
1 hour ago

What is the song at the end of the video ? name ?

@Home-qi6wv
1 hour ago

Thankyou so much sir.😀🙏

@shabnam9519
1 hour ago

I have some navlinks with category name and I want to filter prouducts based on the value(category name) in navlink. My api looks like 'domain-name/ categoryname/limit/startpage'. I did the same and add the categoryname in useeffect hook. But products are not showing. How to do that? @ThapaTechnical

@writterpanditsid5048
1 hour ago

Great

@akashghosh9335
1 hour ago

perfect video

@mohammad-aman1105
1 hour ago

Sir, pro tip. Avoid using index as a key of your component. It will degrade performance

@gamedeeds
1 hour ago

How to make it hit api on horizontal scroll??

50
0
Would love your thoughts, please comment.x
()
x