+Wrapper
ssr: truevike-react/vike-solidYou need
vike-react/vike-solidto be able to use the+Wrappersetting.
The +Wrapper component wraps the +Page component and all +Layout components.
<Wrapper> ⟸ component defined by +Wrapper
<Layout> ⟸ component defined by +Layout
<Page /> ⟸ component defined by +Page
</Layout>
</Wrapper>// pages/+Wrapper.jsx
import React from 'react'
// `children` includes +Page and all +Layout components
export default function Wrapper({ children }) {
return <MyWrapper>{children}</MyWrapper>
}// pages/+Wrapper.tsx
import React from 'react'
// `children` includes +Page and all +Layout components
export default function Wrapper({ children }: { children: React.ReactNode }) {
return <MyWrapper>{children}</MyWrapper>
}The +Wrapper component is usually used for integrating tools, such as tools for data fetching and state management.
The only difference between
+Wrapperand+Layoutis that+Wrapperwraps+Layout.
To integrate tools, we generally recommend
+Wrapperover+Layout, as it ensures that all+Layoutcomponents are also wrapped.To define your pages' visual appearance, we generally recommend
+Layout.
A page can be wrapped by multiple +Wrapper components:
<Wrapper1>
<Wrapper2>
<Wrapper3>
<Layout>
<Page />
</Layout>
</Wrapper3>
</Wrapper2>
</Wrapper1>pageContext
You can access the pageContext object by using usePageContext().
// /pages/+Layout.jsx
import React from 'react'
import { usePageContext } from 'vike-react/usePageContext' // or vike-{vue,solid}
export function Layout({ children }) {
const pageContext = usePageContext()
// ...
}// /pages/+Layout.tsx
import React from 'react'
import { usePageContext } from 'vike-react/usePageContext' // or vike-{vue,solid}
export function Layout({ children }: { children: React.ReactNode }) {
const pageContext = usePageContext()
// ...
}