Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

axios with load more

import React, { useEffect, useState } from "react";
import axios from "axios";
import "./App.css";

const App = () => {
  const [data, setData] = useState([]);
  const [load, setLoad] = useState(10);
  const [flag,setFlag]=useState(true)

  const getData = async () => {
    const res = await axios.get("https://jsonplaceholder.typicode.com/posts");

    setData(res.data);
  };
  useEffect(() => {
    getData();
  }, [])

  const loadData = () => {
    setLoad((prev) => prev + 10)
  }

  return (
    <>
      <div className="data_div">
        {data.slice(0, load).map((item, index) => {
          {/* console.log(data.length) */}

          return (
            <div className="inner" key={index}>
              <h1>{item.id}</h1>
              <h3>{item.title}</h3>
              <p>{item.body}</p>
            </div>
          )
        })
        }
       
       
         {
             load < 100 && <button onClick={loadData}>Load more...</button>
           }
      </div>
    </>
  );
};

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: convert text file to string javascript 
Javascript :: Implementing cascades in mongoose 
Javascript :: jasmine returnvalues example 
Javascript :: code mirror get value from dom 
Javascript :: convert typescript to js online 
Javascript :: 5.1.3. Boolean Expressions&para; 
Javascript :: how to detech my cosle errors in angualr 
Javascript :: How to find object length in vue 
Javascript :: AssertionError [ERR_ASSERTION]: Expected values to be loosely deep-equal: 
Javascript :: change class on resize window jquery 
Javascript :: javascript condition based on table cell value 
Javascript :: typeorm clear cache 
Javascript :: dynamic data fetching in datatable.net 
Javascript :: yarn redux devtool 
Javascript :: add and remove multiple markers on google maps js 
Javascript :: date change error 
Javascript :: Get client or user ip address in react using axios 
Javascript :: how to change sender name in nodemailer 
Javascript :: google.translate.TranslateElement part of page 
Javascript :: javascript string get numbers 
Javascript :: react native red circle bubble 
Javascript :: react break out of useeffect 
Javascript :: javascript update page when json file changes 
Javascript :: array[-1] not working 
Javascript :: change bulk url in elementor 
Javascript :: underscore js shuffle 
Javascript :: strapi login api location 
Javascript :: diable input javascript 
Javascript :: custom render contenful rich text rendering 
Javascript :: como acrescentar item no array js 
ADD CONTENT
Topic
Content
Source link
Name
6+7 =