Skip to content

Server side docs require JSX compiling but don't talk about it #2110

Closed
@kingjerod

Description

@kingjerod

I'm trying to follow the docs on server side rendering, and inside the function handleRender it calls renderToString with JSX elements. Code here:

https://github.com/reactjs/redux/blob/master/docs/recipes/ServerRendering.md

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))
}

This code lives inside the server.js file, alongside the express app. After looking at other parts of the docs, it seems that JSX components are put under the /components directory. Is it implied that this file needs to be compiled also? I don't see anything on that page mentioning that, but otherwise it's not going to work. It seems strange even for the components to have a .js file ending, when they include jsx in them.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions