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

Comments: Load the State from the Session #40

Closed
jayair opened this issue Apr 10, 2017 · 8 comments

Comments

@jayair
Copy link
Member

commented Apr 10, 2017

@jayair jayair added the Discussion label Apr 10, 2017

@jayair

This comment has been minimized.

Copy link
Member Author

commented Jul 27, 2017

@yashg5 The token does expire after an hour but the way the app is set up, when the user refreshes the page we check the session in the Local Storage (the SDK does this) and re-load it.

However, there is a corner case that we are not handling. If the user does not refresh the page within an hour, then the token will expire and you'll get an error. We are going to put out an update to address this soon. But you can easily handle this yourself.

@teejK

This comment has been minimized.

Copy link

commented Oct 7, 2017

Hey, I'm new to javascript, so maybe this is a noob question.
But, we seem to define componentDidMount without calling it?

Do async class methods get called automatically? I can't seem to suss out where it gets called.

EDIT: Nevermind, found it:
https://reactjs.org/docs/react-component.html

@jayair

This comment has been minimized.

Copy link
Member Author

commented Oct 7, 2017

@teejK No worries. Yup part of the React component lifecycle.

@TheDagger

This comment has been minimized.

Copy link

commented Dec 10, 2017

I have a newbie question as well, the line !this.state.isAuthenticating && proceeds after the && to follow with the page to be rendered and a bunch of the html'ish code. How is this working exactly? The way I understand return functions is they return content, true or false. So if the state is currently authenticating it will return true && the content? How do you return both? This is the part that doesn't make sense to me. Likewise how does it return false and the content at the same time? Can a return statement return 2 things back like that? I come from PHP where you could only return 1 thing or you'd have to return a JSON or Array to return multiple types

@jayair

This comment has been minimized.

Copy link
Member Author

commented Dec 11, 2017

@TheDagger Yeah that line is basically using short-circuit evaluation to conditionally render our component.

The short-circuit expression x and y is equivalent to the conditional expression if x then y else false...

So if !this.state.isAuthenticating is true then render our component (return the JSX) or just return false.

Here is a bit more info on it - https://reactjs.org/docs/conditional-rendering.html#inline-if-with-logical--operator

Hopefully that makes sense.

@lepirlouit

This comment has been minimized.

Copy link

commented Dec 21, 2017

It seems not to be a best practice to call setState in the componentDidMount function.

https://github.com/yannickcr/eslint-plugin-react/blob/master/docs/rules/no-did-mount-set-state.md

@jayair

This comment has been minimized.

Copy link
Member Author

commented Dec 21, 2017

@lepirlouit According to the React docs it is okay to call setState in componentDidMount since it handles cases where render gets called twice - https://reactjs.org/docs/react-component.html#componentdidmount

But in this chapter (and other instances in the tutorial) we only call setState asynchronously in componentDidMount. So we shouldn't run into a performance issue.

@jayair jayair closed this May 9, 2018

@jayair jayair reopened this May 9, 2018

@jayair

This comment has been minimized.

Copy link
Member Author

commented May 9, 2018

@jayair jayair closed this May 9, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
4 participants
You can’t perform that action at this time.