Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

README issue: componentDidMount runs in client side only #12

Open
dtonys opened this issue Jul 17, 2017 · 1 comment
Open

README issue: componentDidMount runs in client side only #12

dtonys opened this issue Jul 17, 2017 · 1 comment

Comments

@dtonys
Copy link

dtonys commented Jul 17, 2017

@d-oliveros, for the documentation below

// In the browser, calling 'User.get()' will actually make a HTTP request
// to the server, which will make the actual function call,
// serialize the results back to the browser, and resolve the promise with the value(s).
//
// In the server, 'User.get()' will be called directly
// without doing any HTTP requests or any routing whatsoever.
//
// This same piece of code can be run seamlessly in the browser and the server
export default class MyComponent extends React.Component {
  async componentDidMount() {
    const user = await User.get(123);
    this.setState({ user });
  }
}

"In the server, 'User.get()' will be called directly"

componentDidMount is called on client render only. So perhaps it makes more sense to put this call in componentWillMount to demonstrate it working on the server.

@dtonys
Copy link
Author

dtonys commented Jul 17, 2017

setState in componentWillMount is an anti-pattern, and doesn't defer rendering for server render unless some special treatment is applied, so might not be a beneficial suggestion.

I suppose the example here shows proper server side usage:

// Using the same API on server side

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant