lcbecker.github.io - From Shakespeare to Java

Description: Imagine building a React application where the displayed content depends upon some data coming back from an API call. When one of the navigation tabs …

Example domain paragraphs

Imagine building a React application where the displayed content depends upon some data coming back from an API call. When one of the navigation tabs is clicked at the top of the page, a very specific Component is rendered as the page’s content. This seems like an easy problem to solve, right?

For the sake of this example, let’s say our React app is to display content about buildings. There are many different types of buildings - homes, shops, skyscrapers, monuments, museums, etc. - obviously, the content for each of them is going to be different. If the API response returns back a property like buildingType , we could probably create a switch statement to return the correct component dynamically:

Enter React Router. React Router shows and hides content based on, you guessed it, routes. Usually, React Router is used for single page applications. You can show routes like /new, /edit, or /delete without actually having the entire application refresh. Instead, it simply shows the New component when the /new route is triggered.