I am creating a Choose Your Own adventure browser game. I have realised that all the majority of the data that I want to fill the page (choices, selection etc...) I want to pull from my JSON and dynamically fill the page.
Still, I'll need to create components files to be able to create hooks routes to point at the components locations.
I am sure that there is a way to do this dynamically (instead than create every element manually), but I am pretty new of react, and it doesn't come up anything on top of my mind. I would gladly appreciate any help on the matter.
Example code of a page:
import React from "react";
import Navigation from "components/Navigation/Navigation";
const Page1 = () => {
return (
<>
Page 1
<Navigation room={1} />
</>
);
};
export default Page1;
The value of "room={1}" it is indicating the id of the json is where it will pull the info. I already built this and it works. So I just have to load a number that is growing progressively.
What I want to try to achieve it is to have this piece of component generated to X number of entries that I have in the JSON.
As well I need to generate dynamically this part of the code
<Routes>
<Route path="/cyoa/page1" element={<Page1 />} />
<Route path="/cyoa/page2" element={<Page2 />} />
<Route path="/cyoa/page3" element={<Page3 />} />
<Route path="/cyoa/page4" element={<Page4 />} />
</Routes>
If you could please point me on the right direction I would really appreciate it.
You can find the whole code over here: https://github.com/Littlemad/cyoa