+react
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.ts
// Environment: client
import type { Config } from 'vike/types'
export default {
hydrateRootOptions: {
onUncaughtError,
/*
onCaughtError,
onRecoverableError,
...
*/
},
createRootOptions: {
onUncaughtError
/*
onCaughtError,
onRecoverableError,
...
*/
}
} satisfies Config['react']
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.ts
import type { Config, PageContextClient } from 'vike/types'
export default (pageContext: PageContextClient) => {
return {
hydrateRootOptions,
createRootOptions
}
} satisfies Config['react']
On the server-side, you can set the options of React's renderToString()
.
// pages/+react.server.ts
// Environment: server
import type { Config } from 'vike/types'
export default {
renderToStringOptions: {
identifierPrefix: 'some-id-prefix'
}
} satisfies Config['react']
Make sure you define these in
react.server.js
.