Hamed Sh
Hamed Sh

Reputation: 31

reactjs in browser(local) or on server side?

I'm confused it seems there is 2 way to run reactjs projects 1. in browser between html and script tags 2. not between html and script tags(it runs on browser) but it's different I'm confused. explain it to me plz

Upvotes: 0

Views: 143

Answers (1)

Felipe
Felipe

Reputation: 4375

React is a technology that is rendering custom web components into the browser, when you have a view, let's say dashboard composed of multiple React components, you have two ways to display that to a user:

1/ you display the html that typically contains the root React element and load an associated JavaScript script which contains all the React logic, then fetch the required data of that dashboard, so it will render all your graphs and stuff.

2/ when the user request that specific page, your server application already knows which data are required to render the initial view, so it will compute in advance how the page looks like and send a final first version to the user, it is called server-side rendering. From there obviously the page can be dynamically modified by local JavaScript running in browser afterwards, based on user interaction.

Both approaches have pros and cons, like testing capabilities, speed of execution, and so on... so I encourage you to read about the topic on the web, you can find tons of articles on React server-side rendering that will explain that better than me:

https://www.smashingmagazine.com/2016/03/server-side-rendering-react-node-express/

https://github.com/mhart/react-server-example

Upvotes: 1

Related Questions