Is it possible to generate a static HTML page from a react code and REST API as a trigger? I will provide a use case to describe my issue.
Assuming I'm building a simple notes SPA react app using creat-react-app. The UI allows the user to view the list of all notes, add, edit and delete a note. Clicking on a note will link to that note page which displays more information. The CRUD operations are done with a REST API hosted on a node js server that uses MongoDB as a database.
This notes website is used by a classroom- one teacher has the privilege for CRUD operations while all the students are completely passive and can just view (read) the data. From that perspective, it is obvious that the website the students use could be a completely different react project, and specifically, one static website for the notes list and one for each note- since it only fetches data using the REST API and displays it in a <NoteListItem />
and <NotePage />
react components that are the same for each note.
The static page that displays the entire list could hold a div that fetches the list dynamically, but when clicking on a note the static website of this note will be displayed. When the teacher adds a new note, an API call will be made to my-host/api/addNote and at the end of that controller, I wish to add a function generateStaticPage(noteId)
that will generate that note static page.
This is the basic idea, which implies the use of some known concepts in SSR/react-static where you can define a dynamic scope, static, the template, etc.
A possible solution is a library like react-static, but how can I build a page right after I add a note? Is there any library that can help me achieve this?