Back to Changelog
v1.2.0

May 29, 2024

Improvements to Our SDK

With --watch mode, improved fragmenting, and more, our SDK is growing stronger than ever.


See how all of these improvements work together—sound on

--watch mode

When watch mode is enabled, the SDK automatically updates the generated code in real-time based on the schema changes made in the BaseHub editor.

These are the recommended package.json scripts for a Next.js App:

{
  "scripts": {
    "dev": "basehub dev & next dev",
    "build": "basehub && next build",
    ...
  },
}

basehub dev automatically runs --watch mode for you to simplify the process.

Fragments

Until now, making fragments with the BaseHub SDK was cumbersome. It required managing multiple generated types for each component and using satisfies for type enforcement from the schema into an object.

However, with the introduction of the new fragmentOn function, generating fragments is now effortless, without needing to know the import name, just start typing the Component’s apiName and the autocomplete takes care of the rest. In the second parameter you can set the fragment object safely typed.

// all the imports you need!
import { fragmentOn } from "basehub"

const CalloutFragment = fragmentOn("CalloutComponent", {
  _title: true,
  _id: true,
  type: true,
  content: {
    html: true,
  },
})

export type Callout = fragmentOn.infer<typeof CalloutFragment>

Type-safe Select Blocks

Type safety is a core tenant of our DX. Until today, Select Blocks were typed as a regular string, which meant developers couldn’t actually know what they’d receive. Because Select Blocks are constrained to specific values in the BaseHub dash, one would expect to receive a union of string literals back… So that’s exactly what you’ll get now.

If you constrain a Select Block to “primary“ or “secondary” in the BaseHub dash, you’ll get “primary“ | “secondary” in your IDE.

Get Started

To get started with these new changes, install the latest version of the SDK:

pnpm i basehub@latest