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

Is there a way to share state between the server and the client? #1

Open
sebastianmacias opened this issue Mar 27, 2017 · 0 comments
Open

Comments

@sebastianmacias
Copy link

sebastianmacias commented Mar 27, 2017

For instance in a react/redux serverside rendered application you can pass the state to the client like this:

ie:

import { renderToString } from 'react-dom/server'

function handleRender(req, res) {
  // Create a new Redux store instance
  const store = createStore(counterApp)

  // Render the component to a string
  const html = renderToString(
    <Provider store={store}>
      <App />
    </Provider>
  )

  // Grab the initial state from our Redux store
  const preloadedState = store.getState()

  // Send the rendered page back to the client
  res.send(renderFullPage(html, preloadedState))
}

taken from: http://redux.js.org/docs/recipes/ServerRendering.html

An example that shows how to achieve the equivalent in marko would be very helpful.

I'm just starting to explore marko, amazing stuff so far, congrats

I'm trying to figure out how all the pieces would fit together to build single page isomorphic apps, kind of like what Nuxt does

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