Edit this page

+react setting

Environment: server, client.

Implemented by: vike-react.

You need vike-react to be able to use the +react setting.

Add options to the React functions that vike-react calls.

On the client-side, you can set the options of React's hydrateRoot() and createRoot().

// pages/+react.client.js
// Environment: client
 
export default {
  hydrateRootOptions: {
    onUncaughtError,
    /*
    onCaughtError,
    onRecoverableError,
    ...
    */
  },
  createRootOptions: {
    onUncaughtError
    /*
    onCaughtError,
    onRecoverableError,
    ...
    */
  }
}
 
function onUncaughtError(err) {
  console.error('Uncaught React error', err)
}

Make sure you define these in react.client.js.

You can also use pageContext:

// pages/+react.client.js
 
export default (pageContext) => {
  return {
    hydrateRootOptions,
    createRootOptions
  }
}

On the server-side, you can set the options of React's renderToString().

// pages/+react.server.js
// Environment: server
 
export default {
  renderToStringOptions: {
    identifierPrefix: 'some-id-prefix'
  }
}

Make sure you define these in react.server.js.