0

While rendering react application at server side window, document, jQuery and localStorage are not working.

Can anyone help me with this?

1 Answer 1

2

When you use server side rendering in your application, the first renderer process is done by the server, not by the client (the browser). On the client, we can access to objects like window, document, localStorage, etc. because these all are the property of the browser. However, on the server these objects are not available yet.

I did this scheme a long time ago. It explains the process of renderer in a SSR App. In your case, objects like window will be available only from point 6 (the first green step). Every red step is a server process (here, the properties of the browser are not accesible)

enter image description here

I hope this helps you.

Sign up to request clarification or add additional context in comments.

2 Comments

Is there any alternate to use in my situation ?
I use the library 'mobile-detect' to know if the first request is done by a mobile phone, tablet or desktop. It uses javascript and it can use by the server. To handle data, I use the Redux store of the server and afterwards I provide all information to client in window.INITIAL_STATE object (in the body of HTML)(point 5)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.