vike-react
v0.4.8
Published
<!-- WARNING: keep links absolute in this file so they work on NPM too -->
Downloads
8,218
Readme
vike-react
React integration for Vike, see vike.dev/react.
Introduction
UI framework Vike extensions like vike-react
:
- implement Vike Core hooks (e.g.
onRenderHtml()
) on your behalf, - set Vike Core settings on your behalf,
- introduce new hooks for you to implement if needed,
- introduce new settings for you to set if needed,
- introduce new components and component hooks.
Scaffold new app
Use Bati to scaffold a Vike app using vike-react
.
Add to existing app
To add vike-react
to an existing Vike app:
- Install the
vike-react
npm package in your project:
npm install vike-react
- Extend your existing Vike config files with
vike-react
:
// /pages/+config.js
+import vikeReact from 'vike-react/config'
+
export default {
// Existing Vike Core settings
// ...
+
+ // New setting introduced by vike-react:
+ title: 'My Vike + React App',
+
+ extends: vikeReact
}
Hooks
vike-react
implements the onRenderHtml()
and
onRenderClient()
hooks on your behalf, which are essentially the glue code between
Vike and React.
Settings
vike-react
sets the following Vike Core settings on your behalf:
clientRouting=true
: Enable Client Routing.hydrationCanBeAborted=true
: React allows the hydration to be aborted.
vike-react
introduces the following new settings:
Head
: Component Component to be rendered inside the<head>
tag.title
: string<title>...</title>
tag.favicon
: string<link rel="icon" href="..." />
attribute.lang
: string<html lang="...">
attribute.ssr
: boolean Enable/disable Server-Side Rendering (SSR).stream
: boolean Enable/disable HTML streaming.Layout
: Component Wrapper for your Page component.Wrapper
: Component Another wrapper for your Page component.
Component hooks
vike-react
introduces the following new component hooks:
useData()
: Access the data that is returned by adata()
hook from any component.usePageContext()
: Access thepageContext
object from any component.
Components
vike-react
introduces the following new components:
ClientOnly
: Wrapper to render and load a component only on the client-side.