Fetch more content as user is scrolling down2019 Community Moderator ElectionWhy is React's concept of Virtual DOM said to be more performant than dirty model checking?How to scroll to bottom in react?ReactJS when user scrolls downReact—listen for scroll up / down?How to display a header only after the user starts to scroll down? [React]React native, Redux : Fetch more / Load moreAnimate (Morphing) SVG with scroll down and scroll upGTM trigger as user scrolls down on page in ReactJSScrolling menu up and down in mobile not workingscrolling load more data in React

Is divide-by-zero a security vulnerability?

A bug in Excel? Conditional formatting for marking duplicates also highlights unique value

Can the Shape Water Cantrip be used to manipulate blood?

PTIJ: Aharon, King of Egypt

What does each site of a vanilla 9.1 installation do?

GPL code private and stolen

Where is this quote about overcoming the impossible said in "Interstellar"?

Is there a full canon version of Tyrion's jackass/honeycomb joke?

Are small insurances worth it

How to mitigate "bandwagon attacking" from players?

Giving a talk in my old university, how prominently should I tell students my salary?

Reason why dimensional travelling would be restricted

How can I highlight parts in a screenshot

Meaning of word ягоза

Has Wakanda ever accepted refugees?

In which way proportional valves are controlled solely by current?

How do you say “my friend is throwing a party, do you wanna come?” in german

Should we avoid writing fiction about historical events without extensive research?

Why would the IRS ask for birth certificates or even audit a small tax return?

Sometimes a banana is just a banana

Why do phishing e-mails use faked e-mail addresses instead of the real one?

Why is my Contribution Detail Report (native CiviCRM Core report) not accurate?

Can I solder 12/2 Romex to extend wire 5 ft?

Can an earth elemental drown/bury its opponent underground using earth glide?



Fetch more content as user is scrolling down



2019 Community Moderator ElectionWhy is React's concept of Virtual DOM said to be more performant than dirty model checking?How to scroll to bottom in react?ReactJS when user scrolls downReact—listen for scroll up / down?How to display a header only after the user starts to scroll down? [React]React native, Redux : Fetch more / Load moreAnimate (Morphing) SVG with scroll down and scroll upGTM trigger as user scrolls down on page in ReactJSScrolling menu up and down in mobile not workingscrolling load more data in React










1















I have a page with a search input, once the user click on submit results come up.



There can be a lot of results and I don't want to load them all at once, how can I fetch more data into the page using Lodash throttle on mouse move?



This is my react component:



const getContacts = async (searchString) => 
const data: contactsInfo = await axios.get(`api/Contats/Search?contactNum=$searchString`);
return contactsInfo;
;
export default class Home extends React.Component
state =
contactsInfo: [],
searchString: '',
;

handleSubmit = async () =>
const searchString = this.state;
const contactsInfo = await getContacts(searchString);
this.setState( contactsInfo );
;

onInputChange = e =>
this.setState(
searchString: e.target.value,
);
;

onMouseMove = e =>

;

render()
const contactsInfo, searchString, = this.state;
return (
<div css=bodyWrap onMouseMove=e => this.onMouseMove(e)>
<Header appName="VERIFY" user=user />
user.viewApp && (
<div css=innerWrap>
<SearchInput
searchIcon
value= ''
onChange=e => this.onInputChange(e)
handleSubmit=this.handleSubmit
/>
contactsInfo.map(info => (
<SearchResultPanel
info=info
isAdmin=user.isAdmin
key=info.id
/>
))
</div>
)
<Footer />
</div>

);











share|improve this question


























    1















    I have a page with a search input, once the user click on submit results come up.



    There can be a lot of results and I don't want to load them all at once, how can I fetch more data into the page using Lodash throttle on mouse move?



    This is my react component:



    const getContacts = async (searchString) => 
    const data: contactsInfo = await axios.get(`api/Contats/Search?contactNum=$searchString`);
    return contactsInfo;
    ;
    export default class Home extends React.Component
    state =
    contactsInfo: [],
    searchString: '',
    ;

    handleSubmit = async () =>
    const searchString = this.state;
    const contactsInfo = await getContacts(searchString);
    this.setState( contactsInfo );
    ;

    onInputChange = e =>
    this.setState(
    searchString: e.target.value,
    );
    ;

    onMouseMove = e =>

    ;

    render()
    const contactsInfo, searchString, = this.state;
    return (
    <div css=bodyWrap onMouseMove=e => this.onMouseMove(e)>
    <Header appName="VERIFY" user=user />
    user.viewApp && (
    <div css=innerWrap>
    <SearchInput
    searchIcon
    value= ''
    onChange=e => this.onInputChange(e)
    handleSubmit=this.handleSubmit
    />
    contactsInfo.map(info => (
    <SearchResultPanel
    info=info
    isAdmin=user.isAdmin
    key=info.id
    />
    ))
    </div>
    )
    <Footer />
    </div>

    );











    share|improve this question
























      1












      1








      1








      I have a page with a search input, once the user click on submit results come up.



      There can be a lot of results and I don't want to load them all at once, how can I fetch more data into the page using Lodash throttle on mouse move?



      This is my react component:



      const getContacts = async (searchString) => 
      const data: contactsInfo = await axios.get(`api/Contats/Search?contactNum=$searchString`);
      return contactsInfo;
      ;
      export default class Home extends React.Component
      state =
      contactsInfo: [],
      searchString: '',
      ;

      handleSubmit = async () =>
      const searchString = this.state;
      const contactsInfo = await getContacts(searchString);
      this.setState( contactsInfo );
      ;

      onInputChange = e =>
      this.setState(
      searchString: e.target.value,
      );
      ;

      onMouseMove = e =>

      ;

      render()
      const contactsInfo, searchString, = this.state;
      return (
      <div css=bodyWrap onMouseMove=e => this.onMouseMove(e)>
      <Header appName="VERIFY" user=user />
      user.viewApp && (
      <div css=innerWrap>
      <SearchInput
      searchIcon
      value= ''
      onChange=e => this.onInputChange(e)
      handleSubmit=this.handleSubmit
      />
      contactsInfo.map(info => (
      <SearchResultPanel
      info=info
      isAdmin=user.isAdmin
      key=info.id
      />
      ))
      </div>
      )
      <Footer />
      </div>

      );











      share|improve this question














      I have a page with a search input, once the user click on submit results come up.



      There can be a lot of results and I don't want to load them all at once, how can I fetch more data into the page using Lodash throttle on mouse move?



      This is my react component:



      const getContacts = async (searchString) => 
      const data: contactsInfo = await axios.get(`api/Contats/Search?contactNum=$searchString`);
      return contactsInfo;
      ;
      export default class Home extends React.Component
      state =
      contactsInfo: [],
      searchString: '',
      ;

      handleSubmit = async () =>
      const searchString = this.state;
      const contactsInfo = await getContacts(searchString);
      this.setState( contactsInfo );
      ;

      onInputChange = e =>
      this.setState(
      searchString: e.target.value,
      );
      ;

      onMouseMove = e =>

      ;

      render()
      const contactsInfo, searchString, = this.state;
      return (
      <div css=bodyWrap onMouseMove=e => this.onMouseMove(e)>
      <Header appName="VERIFY" user=user />
      user.viewApp && (
      <div css=innerWrap>
      <SearchInput
      searchIcon
      value= ''
      onChange=e => this.onInputChange(e)
      handleSubmit=this.handleSubmit
      />
      contactsInfo.map(info => (
      <SearchResultPanel
      info=info
      isAdmin=user.isAdmin
      key=info.id
      />
      ))
      </div>
      )
      <Footer />
      </div>

      );








      reactjs






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked 14 hours ago









      user3378165user3378165

      2,41982758




      2,41982758






















          1 Answer
          1






          active

          oldest

          votes


















          0














          I supposed that, using getContacts() you retrieve ALL the contacts, and then you just want to show them at some rate, like showing the first 20, then when you reach the last one, another 20s appear.
          Just asking because this is really different from "let's fetch the first 20 contacts, show them, and when the user reaches the last one, fetch another 20s".



          So, if the first assumption I've made it's correct, I can raccomend you to use the Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API



          This is really useful in case like yours (it's even written in the documentation "Lazy-loading of images or other content as a page is scrolled.").



          The idea is that you should add this Intersection Observer, and start the observation on the last image: this observator will run a callback as soon as the last image appears on the screen (you can even decide the percentage of the image that must be on the screen).
          For example, you can say that, as soon as 1px of the image appear on the screen, you add another 20s images!



          Notice that, once another 20s images are shown, you must unobserve the currect observed image, and observe the new last image!



          I can also suggest to not put the observer on the last image, but maybe on the third last.



          EDIT: I'm not sure this answers your question. It does if I consider the title "Fetch more content as user is scrolling down", but it does not actually use mouseover (even though I think this implementation is the best one for your goal).






          share|improve this answer

























          • Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

            – user3378165
            13 hours ago











          • Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

            – Matteo Gesmundo
            12 hours ago










          Your Answer






          StackExchange.ifUsing("editor", function ()
          StackExchange.using("externalEditor", function ()
          StackExchange.using("snippets", function ()
          StackExchange.snippets.init();
          );
          );
          , "code-snippets");

          StackExchange.ready(function()
          var channelOptions =
          tags: "".split(" "),
          id: "1"
          ;
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function()
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled)
          StackExchange.using("snippets", function()
          createEditor();
          );

          else
          createEditor();

          );

          function createEditor()
          StackExchange.prepareEditor(
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader:
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          ,
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          );



          );













          draft saved

          draft discarded


















          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021264%2ffetch-more-content-as-user-is-scrolling-down%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          I supposed that, using getContacts() you retrieve ALL the contacts, and then you just want to show them at some rate, like showing the first 20, then when you reach the last one, another 20s appear.
          Just asking because this is really different from "let's fetch the first 20 contacts, show them, and when the user reaches the last one, fetch another 20s".



          So, if the first assumption I've made it's correct, I can raccomend you to use the Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API



          This is really useful in case like yours (it's even written in the documentation "Lazy-loading of images or other content as a page is scrolled.").



          The idea is that you should add this Intersection Observer, and start the observation on the last image: this observator will run a callback as soon as the last image appears on the screen (you can even decide the percentage of the image that must be on the screen).
          For example, you can say that, as soon as 1px of the image appear on the screen, you add another 20s images!



          Notice that, once another 20s images are shown, you must unobserve the currect observed image, and observe the new last image!



          I can also suggest to not put the observer on the last image, but maybe on the third last.



          EDIT: I'm not sure this answers your question. It does if I consider the title "Fetch more content as user is scrolling down", but it does not actually use mouseover (even though I think this implementation is the best one for your goal).






          share|improve this answer

























          • Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

            – user3378165
            13 hours ago











          • Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

            – Matteo Gesmundo
            12 hours ago















          0














          I supposed that, using getContacts() you retrieve ALL the contacts, and then you just want to show them at some rate, like showing the first 20, then when you reach the last one, another 20s appear.
          Just asking because this is really different from "let's fetch the first 20 contacts, show them, and when the user reaches the last one, fetch another 20s".



          So, if the first assumption I've made it's correct, I can raccomend you to use the Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API



          This is really useful in case like yours (it's even written in the documentation "Lazy-loading of images or other content as a page is scrolled.").



          The idea is that you should add this Intersection Observer, and start the observation on the last image: this observator will run a callback as soon as the last image appears on the screen (you can even decide the percentage of the image that must be on the screen).
          For example, you can say that, as soon as 1px of the image appear on the screen, you add another 20s images!



          Notice that, once another 20s images are shown, you must unobserve the currect observed image, and observe the new last image!



          I can also suggest to not put the observer on the last image, but maybe on the third last.



          EDIT: I'm not sure this answers your question. It does if I consider the title "Fetch more content as user is scrolling down", but it does not actually use mouseover (even though I think this implementation is the best one for your goal).






          share|improve this answer

























          • Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

            – user3378165
            13 hours ago











          • Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

            – Matteo Gesmundo
            12 hours ago













          0












          0








          0







          I supposed that, using getContacts() you retrieve ALL the contacts, and then you just want to show them at some rate, like showing the first 20, then when you reach the last one, another 20s appear.
          Just asking because this is really different from "let's fetch the first 20 contacts, show them, and when the user reaches the last one, fetch another 20s".



          So, if the first assumption I've made it's correct, I can raccomend you to use the Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API



          This is really useful in case like yours (it's even written in the documentation "Lazy-loading of images or other content as a page is scrolled.").



          The idea is that you should add this Intersection Observer, and start the observation on the last image: this observator will run a callback as soon as the last image appears on the screen (you can even decide the percentage of the image that must be on the screen).
          For example, you can say that, as soon as 1px of the image appear on the screen, you add another 20s images!



          Notice that, once another 20s images are shown, you must unobserve the currect observed image, and observe the new last image!



          I can also suggest to not put the observer on the last image, but maybe on the third last.



          EDIT: I'm not sure this answers your question. It does if I consider the title "Fetch more content as user is scrolling down", but it does not actually use mouseover (even though I think this implementation is the best one for your goal).






          share|improve this answer















          I supposed that, using getContacts() you retrieve ALL the contacts, and then you just want to show them at some rate, like showing the first 20, then when you reach the last one, another 20s appear.
          Just asking because this is really different from "let's fetch the first 20 contacts, show them, and when the user reaches the last one, fetch another 20s".



          So, if the first assumption I've made it's correct, I can raccomend you to use the Intersection Observer API https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API



          This is really useful in case like yours (it's even written in the documentation "Lazy-loading of images or other content as a page is scrolled.").



          The idea is that you should add this Intersection Observer, and start the observation on the last image: this observator will run a callback as soon as the last image appears on the screen (you can even decide the percentage of the image that must be on the screen).
          For example, you can say that, as soon as 1px of the image appear on the screen, you add another 20s images!



          Notice that, once another 20s images are shown, you must unobserve the currect observed image, and observe the new last image!



          I can also suggest to not put the observer on the last image, but maybe on the third last.



          EDIT: I'm not sure this answers your question. It does if I consider the title "Fetch more content as user is scrolling down", but it does not actually use mouseover (even though I think this implementation is the best one for your goal).







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited 12 hours ago









          user3378165

          2,41982758




          2,41982758










          answered 14 hours ago









          Matteo GesmundoMatteo Gesmundo

          341315




          341315












          • Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

            – user3378165
            13 hours ago











          • Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

            – Matteo Gesmundo
            12 hours ago

















          • Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

            – user3378165
            13 hours ago











          • Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

            – Matteo Gesmundo
            12 hours ago
















          Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

          – user3378165
          13 hours ago





          Thank you for your answer, I'm not sure what makes the most sense, I think fetching more data from the API would make more sense rather than getting all contacts once.

          – user3378165
          13 hours ago













          Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

          – Matteo Gesmundo
          12 hours ago





          Well, I think it mostly depends on how many contacts there would be, at most. And how "big" is a contact, in terms of bytes. If it was me, I would fetch all the contacts at once if they are 100-200 or less.. Then you may also consider "how frequently could happen that the user will scroll and require other contacts?".. Anyway, in both cases, using the Intersection Observer is THE solution: instead of just displaying new images, the callback will run a new fetch API, and retrieve new contacts. You can also add a loading spin effect using the Promise of that fetch :)

          – Matteo Gesmundo
          12 hours ago



















          draft saved

          draft discarded
















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid


          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.

          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function ()
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55021264%2ffetch-more-content-as-user-is-scrolling-down%23new-answer', 'question_page');

          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Save data to MySQL database using ExtJS and PHP [closed]2019 Community Moderator ElectionHow can I prevent SQL injection in PHP?Which MySQL data type to use for storing boolean valuesPHP: Delete an element from an arrayHow do I connect to a MySQL Database in Python?Should I use the datetime or timestamp data type in MySQL?How to get a list of MySQL user accountsHow Do You Parse and Process HTML/XML in PHP?Reference — What does this symbol mean in PHP?How does PHP 'foreach' actually work?Why shouldn't I use mysql_* functions in PHP?

          Compiling GNU Global with universal-ctags support Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) Data science time! April 2019 and salary with experience The Ask Question Wizard is Live!Tags for Emacs: Relationship between etags, ebrowse, cscope, GNU Global and exuberant ctagsVim and Ctags tips and trickscscope or ctags why choose one over the other?scons and ctagsctags cannot open option file “.ctags”Adding tag scopes in universal-ctagsShould I use Universal-ctags?Universal ctags on WindowsHow do I install GNU Global with universal ctags support using Homebrew?Universal ctags with emacsHow to highlight ctags generated by Universal Ctags in Vim?

          Add ONERROR event to image from jsp tldHow to add an image to a JPanel?Saving image from PHP URLHTML img scalingCheck if an image is loaded (no errors) with jQueryHow to force an <img> to take up width, even if the image is not loadedHow do I populate hidden form field with a value set in Spring ControllerStyling Raw elements Generated from JSP tagds with Jquery MobileLimit resizing of images with explicitly set width and height attributeserror TLD use in a jsp fileJsp tld files cannot be resolved