React: Is there any way to use componentDidMount() when rendering via node server
up vote
0
down vote
favorite
So I'm quite new to react and node, and found it easiest for me to use node (express) server and then just linking to react using CDN. Until now everything has worked fine this way, but I would like to use something like componentDidMount() for rendering a list of books. Googled a little and found out that componentDidMount() is not fired when rendering via the server. So I was wondering if there is an alternative way, that can do the same thing. Tried with componentWillMount() as well, but no change.
Thanks for any advice
node.js reactjs express
add a comment |
up vote
0
down vote
favorite
So I'm quite new to react and node, and found it easiest for me to use node (express) server and then just linking to react using CDN. Until now everything has worked fine this way, but I would like to use something like componentDidMount() for rendering a list of books. Googled a little and found out that componentDidMount() is not fired when rendering via the server. So I was wondering if there is an alternative way, that can do the same thing. Tried with componentWillMount() as well, but no change.
Thanks for any advice
node.js reactjs express
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
So I'm quite new to react and node, and found it easiest for me to use node (express) server and then just linking to react using CDN. Until now everything has worked fine this way, but I would like to use something like componentDidMount() for rendering a list of books. Googled a little and found out that componentDidMount() is not fired when rendering via the server. So I was wondering if there is an alternative way, that can do the same thing. Tried with componentWillMount() as well, but no change.
Thanks for any advice
node.js reactjs express
So I'm quite new to react and node, and found it easiest for me to use node (express) server and then just linking to react using CDN. Until now everything has worked fine this way, but I would like to use something like componentDidMount() for rendering a list of books. Googled a little and found out that componentDidMount() is not fired when rendering via the server. So I was wondering if there is an alternative way, that can do the same thing. Tried with componentWillMount() as well, but no change.
Thanks for any advice
node.js reactjs express
node.js reactjs express
asked Nov 22 at 8:08
Aron Nicholasson
185
185
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47
add a comment |
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
accepted
It is not possible. In an isomorphic react app, componentDidMount
will only be called after the hydration is done in the client.
So, if you want to render something based on props or state, you can use the class constructor
or the legacy componentWillMount
as these methods will be called during render done in node.
Hope this helps!
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
accepted
It is not possible. In an isomorphic react app, componentDidMount
will only be called after the hydration is done in the client.
So, if you want to render something based on props or state, you can use the class constructor
or the legacy componentWillMount
as these methods will be called during render done in node.
Hope this helps!
add a comment |
up vote
0
down vote
accepted
It is not possible. In an isomorphic react app, componentDidMount
will only be called after the hydration is done in the client.
So, if you want to render something based on props or state, you can use the class constructor
or the legacy componentWillMount
as these methods will be called during render done in node.
Hope this helps!
add a comment |
up vote
0
down vote
accepted
up vote
0
down vote
accepted
It is not possible. In an isomorphic react app, componentDidMount
will only be called after the hydration is done in the client.
So, if you want to render something based on props or state, you can use the class constructor
or the legacy componentWillMount
as these methods will be called during render done in node.
Hope this helps!
It is not possible. In an isomorphic react app, componentDidMount
will only be called after the hydration is done in the client.
So, if you want to render something based on props or state, you can use the class constructor
or the legacy componentWillMount
as these methods will be called during render done in node.
Hope this helps!
answered Nov 22 at 8:16
Pranesh Ravi
9,11812246
9,11812246
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53426387%2freact-is-there-any-way-to-use-componentdidmount-when-rendering-via-node-serve%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What's your case? If it's an operation that you cannot use a constructor for, it's likely unsuitable for SSR.
– estus
Nov 22 at 8:11
was thinking to fetch data, and then displaying it on page render
– Aron Nicholasson
Nov 22 at 8:25
Do you intend to render fetched data on server sdie?
– estus
Nov 22 at 8:31
The plan was to render on client side, i have a method in React class that sends a fetch(), method: Get request to the server that executes a query to the database and sends the response back to the client
– Aron Nicholasson
Nov 22 at 8:39
Currently SSR is synchronous. A request likely shouldn't be coupled with a component then. Fetch it separately, pass hydration data to client side. Things are expected to change in 17.
– estus
Nov 22 at 8:47