The URL is dynamic
url/:id/:name (using Reach Router)
url/1/name1
url/2/differnet-link
url/3/another-link
In Article Component, I want to load 1.json if the URL is url/1/name1 or 2.json if the URL ID is 2
import menuArray from '../data/menu.json';
This is how I usually load JSON in ReactJS
class Article extends React.Component {
constructor(props) {
super(props);
if(/* id is available in the menuArray */) {
// I want to load the JSON by id and store it in state
}
}
}
What is the optimal solution to load dynamic JSON file in ReactJS?