I heard that Facebook, Discord, etc were built with ReactJS, a single webpage application, however, im not seeing that.
Sorry, this might be a silly question but how is Facebook a ReactJS application if ReactJS apps are supposed to be a single webpage. If you look at the web address while on Facebook it keeps changing as you navigate through it.
2
Answers
Facebook is a ReactJS SPA. Despite changing URLs, it doesn’t load new pages in the traditional sense. Instead, it uses ReactJS to dynamically update the content on the same page. The browser’s History API is used to change the URL without a full page reload, creating the appearance of navigating through different pages. This is achieved through React’s component-based architecture, where components like the news feed or comments are updated independently.
See this Code below, here we’re using React Router, to load each component:
In this example,
Router
manages the application’s navigation. Clicking on the links changes the URL without reloading the page, and the<Route>
components render different content based on the current URL, demonstrating how a React SPA can handle navigation while remaining on a single page.It’s like an index page of a book, where you can see the page names and page numbers listed. So, the complete wrapper remains the same (I.e. the book) but the pages change.
"Single Page Application" means that the app gets loaded from a single page (typically named
index.html
), which then loads a bunch of JavaScript to manipulate what is displayed in the browser while that one page remains loaded.React is a JS library (some say "framework") that standardizes and unifies many previously disparate programming practices for building SPAs.
One of the more popular concepts that a few React libraries (e.g.
react-router-dom
) make available is the ability to "change pages" including changing the URL in the browser…all the while actually remaining on that same initialindex.html
page. No new JS gets loaded …. or, at least, the initial JS loaded byindex.html
remains loaded.React doesn’t actually have any programming objects named "pages". React’s primary programming element is called a "component" and it is entirely up to the programmer to determine the boundaries of their components. A component could be "a whole screen" of information, or just a button or a text field or whatnot.
Frequently in React projects you will have some components organized into directories called "pages" while others might be in "common" or "menus" or "navigation". But all of this is up to the programmer to decide how they’d like to organize their code.
BTW: to the best of my knowledge, Discord is written in Expo/React-Native.