I would like to be able to retrieve data from an API, server-side, and load it into React context, in order to make it available to any component in my app. I have tried various things, but nothing seems to allow me to do exactly what I want. Some things I've tried include:
getServerSideProps - This allows me to retrieve the data, server-side, but only exists for Page components, so if I want this available on every page, and I don't know which page my user will land on, I'll need to add logic for this to every single page.
getInitialProps in _app.js - I can add this to the _app.js component, which will run server-side, and can make it available to all components via a context provider, but the problem is that it runs on every single page, even when navigating client-side. I would like to be able to call the API once and only once, and this doesn't seem to allow that.
getInitialProps in _document.js - I can add this to the _document.js component, which only runs on the server, which seems to address the problem of it being called for every page, but I cannot figure out how to store it in React context from there. In fact, I can't seem to figure out how to access this data anywhere. It looks like getInitialProps in _document.js is called after getInitialProps in _app.js, so I'm not sure if I can use the value I generate from getInitialProps in _document.js when I am in _app.js.
There are a number of ways I can make this work if I call the API on the client, but that won't work for my use case as it will cause a flash of content when the client updates with the data from the API.
Another novelty of Next.js app folder, is that now, server-side code is not limited to page-level getServerSideProps anymore. Nested component can also be Server Components and trigger server calls. Therefore, you might sometimes not only want to setup a client-side context, but also a kind of server-side context, scoped to the current request.
A note on naming: I've be using the term "server context" to designate data stored in cache that acts as a context. It's because it's the server-side equivalent of the "client" context.However, "Request cache" is perhaps more suited, as "server context" may be used for an other purpose in future versions of Next.js and React (sharing data between RSC and client components).
For RSC, the "cache" function allows to implement "cached getters", you don't really pass the values around but instead you call the function to get the value. Thanks to caching, the value is actually retrieved only once, your database or API won't be overloaded with requests.
In rare situations, this is not possible to use this approach, namely if you want to derive a value from the page props (rather than fetching data from an API/database) and pass it to children without props drilling.
The server-only-context package implements an alterative "get/set" pattern for mimicking a context with RSC. You can set a value in the page, and access it in the component.Be mindful that you can't guarantee that a layout is rendered before a page (because of client-side navigation), so you can't set a value from a layout and get it from a page. Hopefully, this pattern is never strictly needed.
hi, how to set up an Indesign document to design a magazine? facing pages or single pages?
Generally I have always set up facing pages, the problem is that recently I was then told that the pdf had to
be exported on a single page, which then caused me problems for the images that covered two facing pages.
What is the exact procedure when the pdf has to be exported on a single page but you set the job to facing pages,
also because the previews of the pdf will then be shown to the customer with the facing pages? I hope I was clear
It's a little unclear what you are asking for here but if the goal is to break your spreads down to single pages for the pdf then simply choose "Pages" in the General section of the Export Adobe PDf dialog window which appears when you export a pdf using File>Export>Adobe PDF (Print).
If your goal is to make the InDesign file into single pages then go through File>Document Setup and uncheck Facing Pages. If "Allow Document Pages to Shuffle" is checked in the Pages Panel pull-down menu then the spreads will all automatically change to single pages. If that option is unchecked then the spreads will remain in their original configuration (although it now will have the apperance in the Pages Panel of a single page document) but you will now be able to manually separate them into single pages.
You will design the magazine as a facing pages document, and when you supply the files to your printer, you will generate single page PDFs. The printer has imposition software where they arrange the pages as they need to for a signature, with things like creep and bottling (I won't explain what these are because it's not your worry) to account for the folding of the paper. In very rare circumstances they may come back and ask for a particular page for a specific bleed situation, but this is rare.
If you want, you can create proof PDFs for your client in spreads (as some has mentioned); it helps them picture the flow across a spread, but if they want to print it out, they will probably just have a typical office printer so leaving as single pages is still better for them to handle.
I believe I understand your problem. I'm going to go on the assumption that you're finding when you export single page PDFs for your printer that your crossover images are appearing on one page and not the other.
Check with your printer to see if they have a more convenient solution for you, but the default fix for handling problems with preparing a crossover image across two-page spreads is to place two of them.
This is the easiest way I've found to ensure, with no ifs, ands or buts that I've got perfect placement for crossover images when my printer turns the output PDF from single-page layout to printer's spreads to print my job. This takes work, but if you do it right it's absolutely bulletproof.
Thanks everyone for the answers and sorry for the bad English. I try to better explain what my problem is.
I set up my Indesign document with facing pages and 5 mm of trim on the sides of the pages.
Now, if I have to set a photo on a page that goes to the whole page, that is, that is cut at the extreme edge of the page (as in the figure below), I have to lengthen the image by 5 mm which will then be cut by the printer.
However, when I have to show the client the magazine's drafts with the facing pages, they will also see those 5 mm of photos end up on the side page. I can't edit all the photos by hand :-(.
So, the problem is not to modify the document from facing pages to single pages (when I have to send it to the printer), but to make sure that with facing pages I do not have to manually modify all the images that overlap (by 5 mm) on the opposite page.
I haven't been clear yet. My problem is not related to the printing of the magazine; that's not a problem. I delivered the pdf on a single page and with the 5 mm cut and stop, the printer then printed it normally with the facing pages.
My problem comes up when I have to show the client the pdf on facing pages. With facing pages, the customer will also see those 5mm of photos that they shouldn't see, and that won't print.
You will make a "proof" pdf for your client that does not include the bleed (as set in your marks and bleed settings when you export). Then when you are ready to send to the printer, you will make "print ready" files that do include the bleed. Simple as that
Arghh it's so hard for me to make people understand what I mean in another language.
If I in my facing page document I set the photo up to the edge of the side page, then not with the 5 mm (trim) that extends on the side page I extend, when I then go to set the single page document, the photo it will extend to the edge of the page, and not with the 5mm cut.
The printer (the man who print the magazine) will tell me that that single page will not do well because the photo does not have a 5 mm cut and that in the print it could leave a little white. PRATICALLY, the photos that end at the edge of the page must always have this extra 5 mm.
The bleed is necessary on the OUTSIDE edges only in a saddle-stitch booklet, as that where the paper is being trimmed, not at the fold. You can totally leave your photo at "0" at the fold edge (as in your illustration).
Now, if there is a need by your printer to have bleed on the spine edge (if they are trimming to single pages to wire bind, for instance), then, yes, change your document to single pages, and make left and right master pages and apply them alternately throughout your document. It's a bit harder as a designer to work with as you have to things like do photo crossovers manually on two pages, instead of naturally on a spread, but it's doable.
"You will make a "proof" pdf for your client that does not include the bleed" How??what is the procedure to ensure that in the test pdf the photos that cover the whole page and with the 5 mm, are seen without those 5 mm?
1) Ho impostato un magazine in InDesign partendo da pagine affiancate.
2) Le prove del documento da far vedere al cliente devono essere con le pagine affiancate non a pagina singola.
3) Lo stampatore chiede che il pdf da stampare gli sia inviato per a pagine singole e non accoppiate, e con 5 mm di rifilo su tutti i lati della pagina.
4) Nel magazine, su alcune pagine, ci sono delle immagini che coprono tutta la pagina.
5) Per realizzare nel modo corretto queste immagini che coprono tutta la pagina, devono essere quindi "allungate" di 5 mm anche sul documento a pagine affiancate perch, in caso contrario, sul documento a pagina singola l'immagine apparir come questa nella immagine, cio senza il rifilo, cosa che lo stampatore invece mi ha chiesto.
6) Ora se io per il cliente esporto il pdf a pagine affiancate, quella immagine che copre tutta la pagina, mi apparir come questa nella immagine, cio con i 5 mm di rifilo che finiscono sulla pagina di fianco.
Come fare quindi per esportare il pdf a pagine affiancate e fare in modo che i 5 mm di rifilo nel lato interno della pagina non si vedano?