-
Notifications
You must be signed in to change notification settings - Fork 293
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
[redux-ssr] Question about hasServerState, setServerState and cleanServerState #308
Comments
You can have a look at https://github.com/gabrielbull/react-router-server to understand it better.
When I call Explaining the flow: componentWillMount() {
const { readList, hasServerState, setServerState, cleanServerState } = this.props
if (!hasServerState) {
if (isServer) {
// on server, it fetches data and sets server state so it can be sent to the client within react-router-server
readList().then(setServerState, setServerState)
} else {
// this is the second time you open the page on the client
readList()
}
} else if (isBrowser) {
// this is the first time you open the page on the client.
// There's already data sent by the server, so it doesn't need to be fetched again.
// It just cleans server state so the second time you open that page will refresh data.
cleanServerState()
}
} |
Thanks for the answer it is a little bit clearer but because the example is using redux.
I think this |
maybe this react router server state should just contain flags saying: |
Yeah, that works like a flag. For better clarity, maybe we should change the const withServerState = fetchState(
state => ({
hasServerState: !!state.postListLoaded,
}),
actions => ({
setServerState: () => actions.done({ postListLoaded: true }),
cleanServerState: () => actions.done({ postListLoaded: false }),
})
) |
I have trouble understanding those 3 variables that are used for SSR.
For example, I would like to understand that is the role of those variable for the container PostList.js
hasServerState: !!state.data,
I am wondering when this conditional is true?I do not see the
data
property anywhere on the redux state. Where does state.data come from?Is it within the scope of the selector or is it the root state object?
setServerState
call the done function with{ data }
where does this data go ? I guess this is not operating at the root level of the state, is it?cleanServerState
just call done. What is the purpose of this function ?Is there other use case where cleanServerState does a little more that that ?
Thanks for the good work.
Cheers
The text was updated successfully, but these errors were encountered: