0

Stack: nextjs (yes, I'm using SSR), Hasura, reactjs

I have 2 pages, one of them queries and displays a table that contains users. Another page is for printing the said table using window.print().

So basically, the said 2 pages use the same data.

I am thinking of 2 ways to tackle this:

  1. On the 2nd page, use the same query as I have on the first page (which sounds redundant and not efficient)

  2. Pass the data from the 1st page on the 2nd page's URL (which is will make the URL dirty but it sounds faster)

zai
  • 131
  • 2
  • 6
  • 1
    You should use a global state management package like `MobX` or `Redux`. This will allow you to store the data in a global state and use it in the second page. – Roc Khalil May 17 '19 at 09:16
  • 1
    You could make use of React **context**. The Next.js repo has an example here: https://github.com/zeit/next.js/tree/master/examples/with-context-api – Steve Holgado May 17 '19 at 12:32
  • @RocKhalil im quite aware of these techs, however, im not sure if i should redo everything just to cater to this problem – zai May 20 '19 at 03:43
  • @SteveHolgado contexts are pretty useful and thank you for the suggestion but I really just want to know what are the ups and downs between the 2 ways aforementioned – zai May 20 '19 at 03:45
  • 1
    @zai IF you don't want to integrate MobX or Redux, then it's better to use the same query twice. You should also take into consideration the abstraction of this query instead of re-writing it several times in your app. Add to that, even with adding MobX or Redux, you'll also need to query the data again when the global state is empty (i.e: someone opens the link directly). – Roc Khalil May 20 '19 at 08:12
  • @RocKhalil I see, that makes sense. But why should I query it again when there's the option of storing it in the URL parameters. I don't mean to force the 2nd way but what's the con? – zai May 21 '19 at 02:56
  • 1
    @zai I personally hate long urls; it's a personal preferences, that's it :-p I also don't know how many characters a url / param can handle to be honest – Roc Khalil May 21 '19 at 07:42
  • @RocKhalil hahaha alright man. Thank you so much for the clarification and insights, I appreciate it a lot. Is there any way in Stack wherein I can show my gratitude? – zai May 22 '19 at 02:48
  • 1
    @zai thank you :-) I think you can upvote the comment and that's it :-p anyway, no need to, I'm just here to help :-) – Roc Khalil May 22 '19 at 05:42
  • @RocKhalil i can't upvote, idk why :'< but yeah, thank you for your help! – zai May 22 '19 at 09:13

0 Answers0