<Pump />
A React Server Component that queries BaseHub and can subcribe to real time changes seamlessly.
import { Pump } from 'basehub/react-pump'
Pump is a React Server Component, meaning, it can only be used within frameworks that support RSC (Next.js only for now).
The power of Pump comes when you use Next.js Draft Mode alongside it. Pump lets developers write their queries and rendering logic in a simple and typesafe way, and get “content fast refresh” (live preview) out of the box, without affecting the website’s performance in any way.
If you’re interested in how this works under the hood, or the reason behind its syntax, you can read our blog post about it.
Props
These are the props supported by <Pump />
.
Example
This query will get _sys.id
from the API. Most importantly, when Next.js Draft Mode is enabled, it’ll subscribe to content changes in real time.
import { Pump } from "basehub/react-pump"
import { draftMode } from "next/headers"
const Page = () => {
return (
<Pump
queries={[{ _sys: { id: true } }]}
draft={draftMode().isEnabled}
next={{ revalidate: 30 }}
>
{async ([data]) => {
"use server"
return (
<pre>
<code>{JSON.stringify(data, null, 2)}</code>
</pre>
)
}}
</Pump>
)
}
export default Page