Key concepts
- Editor configuration lives in
src/views/admin/editor/components/useEditorConfiguration.tsxand uses Puck (@measured/puck) to declare components, fields, categories and render functions. - Components that need data typically accept a
mockDataprop and delegate fetching to ause*Datahook which supports an optionalmockDataoverride. - Mock payloads are colocated in
src/views/admin/editor/mockData/mocks/*.tsand are lazy-loaded via a small helper hook.
How mock data works
-
Opt-in at the editor field level
- Most components include a
withMockDatafield and default it totruein the editor only. useEditorConfigurationprovideswithMockDataFieldswhich you can spread into a component’sfields.
- Most components include a
-
Load the data
- Editor render functions call
useMockedData(Name, inEditor && props.withMockData)and pass the result to the presentational component asmockData. - The hook is defined in
src/views/admin/editor/mockData/mockedData.ts.
- Editor render functions call
-
Provide a mock module
- Place a file named exactly like the editor component key in
src/views/admin/editor/mockData/mocks/. - Export
getMockData(business?: any)which returns the mocked payload.businessis provided by the current route context and helps match currency, branding, etc.
- Place a file named exactly like the editor component key in
The useMockedData hook
Source: src/views/admin/editor/mockData/mockedData.ts
- Uses
import.meta.glob('./mocks/*.ts')to lazily import{Name}.ts. - Calls
getMockData(business)if present and returns its result. - When
loadDatais false, returnsundefinedso live fetching occurs.
The data hooks contract
Data hooks (for exampleuseFaqData, useBlogData, useProductsData, usePredictiveBookingsData) call useData/useTypedData from src/api/fetchData.ts.
- They accept an optional
mockDataparameter. useDatashort-circuits and returns{ resource: mockData, isLoading: false }ifmockDatais provided, otherwise it performs the real HTTP call.- Hooks also declare response shapes via
createShape(...)to limit fields and enable server-side shaping.
Adding a new editor component
-
Create the UI component
- Add a presentational component under
src/views/admin/editor/components/editorComponents/v1/YourComponentEC.tsx. - The component should accept an optional
mockDataprop (typed to the shape your data hook expects) and pass it to the relevantuse*Datahook, or consume it directly if it doesn’t fetch.
- Add a presentational component under
-
Add mock data (optional but recommended)
- Create
src/views/admin/editor/mockData/mocks/YourComponent.tsexportinggetMockData(business?: any). - Return a payload that matches what your UI expects. You can import and reuse other mocks to keep parity across variants.
- Create
-
Register the component in the editor
- Open
src/views/admin/editor/components/useEditorConfiguration.tsx. - Add a lazy import for your
YourComponentEC. - Extend the
Componentstype with aYourComponent: {}entry. - Add a config entry under
componentswith:labelfields(include...withMockDataFieldsif you support it)defaultProps(often{ withMockData: true })render: (props) => { const mockData = useMockedData('YourComponent', props.editMode && props.withMockData); return <YourComponentEC {...props} mockData={mockData} /> }
- Optionally, add it to a
categoriesgroup so it appears in the editor palette.
- Open
-
Wire a data hook (if needed)
- In your
YourComponentEC, call the relevantuse*Data(mockData)hook and pass its return to the presentational child. - Example pattern:
- In your
Naming rules and gotchas
- File naming must match the editor key exactly. If your key is
UpcomingEventsDashboardSection, the mock file must beUpcomingEventsDashboardSection.ts. getMockDatacan accept thebusinessobject to tailor outputs (currency, business name, web address).- When outside the editor (live runtime),
withMockDatahas no effect—mock hook returnsundefinedand real requests run. - Keep mock payloads small and representative. Prefer a handful of items and realistic field names so the UI matches production.
Example: FAQ section
- Editor config:
- In
useEditorConfiguration, theFaqPageSectionentry setsdefaultProps: { withMockData: true }and passesmockDatato<FaqPageSectionEC/>.
- In
- Mock file:
src/views/admin/editor/mockData/mocks/FaqPageSection.tsexports several FAQ articles.
- Data hook:
src/views/faq/useFaqData.tsxacceptsmockDataand passes it intouseTypedData(..., { mockData }).
Troubleshooting
- “No mock module found” error: ensure the mock filename matches the editor component name and lives under
mockData/mocks/. - Mock renders but shape mismatch: align the mock payload with the
shapeyour data hook requests. - Not seeing mock vs live toggle: make sure the component spreads
...withMockDataFieldsand usesprops.editModeto guard loading.
Checklists
When adding a component:- UI component under
editorComponents/v1 - Mock under
mockData/mockswithgetMockData - Editor registration in
useEditorConfiguration - Category placement
- Optional data hook integration that respects
mockData