Hooks

useDocyrusDummyDataGeneratorWizard

One-call wiring of a Docyrus data source to the native DummyDataGenerator. Loads the schema, seeds per-field strategies, generates seeded sample rows, previews and exports them, and inserts them into the data source. Returns an inline wizard element plus imperative helpers.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-dummy-data-generator-wizard
Required Packages(5 packages)
pnpm add @docyrus/api-client @docyrus/app-utils @tanstack/react-query expo-file-system (optional) expo-sharing (optional)

This is a port of the web hook with the same options and result. It needs an authenticated RestApiClient and a QueryClientProvider above it. It renders DummyDataGenerator. expo-file-system and expo-sharing are optional peers used only by the preview step's export menu.

How it works

  1. Fields. Target fields come from useDocyrusDataSourceFields (cache-first through the shared inventory), unless you pass fields. Whenever the field list changes, strategies are rebuilt with buildInitialStrategyMap, keeping the ones the user already edited.
  2. Generate. Preview rows generates count rows with a fresh random seed through the pure generateDummyRows. Regenerate sample re-rolls the seed. User fields draw from users, and relation fields draw from relationOptionsByFieldSlug. The hook does not fetch either pool, so relation fields stay empty without it.
  3. Insert. Save to data source inserts every generated row with, in order of preference, insertRecords, collection.createMany({ records }), per-row collection.create(row), or per-row POST /v1/apps/{appSlug}/data-sources/{dataSourceSlug}/items. Per-row failures are collected into the result. With previewOnly, nothing is posted and Finish produces a result with totalCreated: 0.

Usage

import { useDocyrusClient } from '@docyrus/signin/react-native';

import { AwesomeDialog, AwesomeDialogBody, AwesomeDialogContent } from '@/components/docyrus-native/awesome-dialog';
import { useDocyrusDummyDataGeneratorWizard } from '@/hooks/docyrus-native/use-docyrus-dummy-data-generator-wizard';

export function SeedTasks({ open, onOpenChange, users }: Props) {
  const client = useDocyrusClient();
  const { wizard } = useDocyrusDummyDataGeneratorWizard({
    client: client!,
    appSlug: 'base',
    dataSourceSlug: 'task',
    requiredFieldSlugs: ['name'],
    defaultCount: 25,
    users,
    enabled: open,
    onGenerated: result => console.log(`${result.totalCreated} created`)
  });

  return (
    <AwesomeDialog open={open} onOpenChange={onOpenChange} container="sheet" side="bottom" size="full">
      <AwesomeDialogContent>
        <AwesomeDialogBody>{wizard}</AwesomeDialogBody>
      </AwesomeDialogContent>
    </AwesomeDialog>
  );
}

The wizard is an inline element, so wrap it in your own dialog or sheet for modal use.

API Reference

Options (UseDocyrusDummyDataGeneratorWizardOptions)

OptionTypeDefaultDescription
clientRestApiClient—Authenticated REST client (required).
appSlugstring—App slug (required).
dataSourceSlugstring—Data source slug (required).
appIdstring—Accepted for web parity (web scopes its saved-view lookup by app id).
fieldsReadonlyArray<DocyrusFieldLike>—Pre-resolved target fields. Skips the schema fetch.
requiredFieldSlugsReadonlyArray<string>[]Slugs that must stay enabled.
defaultCountnumber10Initial number of records.
maxCountnumber1000Hard cap for the record count.
previewRowCountnumber10Rows shown in the preview step.
collection{ create?: (input) => Promise<unknown>; createMany?: (input: { records }) => Promise<unknown> }—Collection wrapper. createMany is preferred for batch inserts.
usersReadonlyArray<DummyUserOption>—Tenant users for user fields.
relationOptionsByFieldSlugRecord<string, ReadonlyArray<DummyRelationOption>>—Relation pools keyed by field slug. Without them, relation fields are not generated.
previewOnlybooleanfalseNever POST; the preview step ends with Finish (download-only flows).
enabledbooleantruefalse returns wizard: null and skips the schema fetch.
onGenerated(result: DummyGenerationResult, rows: ReadonlyArray<Record<string, unknown>>) => void—Called after the insert (or Finish) completes.
onError(error: Error, rowIndex: number) => void—Called when a per-row insert throws.
insertRecords(rows) => Promise<{ errors: ReadonlyArray<{ rowIndex: number; message: string }> }>—Replace the insert logic.
titleReactNode—Wizard header title.
descriptionReactNode—Wizard header description.
iconstring—Wizard header icon.
exportFileNamestring'<dataSourceSlug>-dummy-data'File name (without extension) for exports.

Result (UseDocyrusDummyDataGeneratorWizardResult)

FieldTypeDescription
wizardReactElement | nullThe wired inline DummyDataGenerator.
resetWizard() => voidBack to the configure step. Clears the generated rows and the result.
stepDummyDataGeneratorStepCurrent step.
setStep(next: DummyDataGeneratorStep) => voidChange the step.
generateAsync() => ReadonlyArray<Record<string, unknown>>Generate rows with a new seed (synchronous) and store them.
insertAsync(rows) => Promise<DummyGenerationResult>Insert rows and resolve the result.
fieldsReadonlyArray<DocyrusFieldLike>Resolved target fields.
strategiesDummyStrategyMapCurrent strategies.
setStrategies(next: DummyStrategyMap) => voidReplace the strategies.
countnumberCurrent record count.
setCount(next: number) => voidChange the count.
generatedRowsReadonlyArray<Record<string, unknown>>Rows of the latest generation.
resultDummyGenerationResult | nullResult of the latest insert.
isGeneratingbooleanAlways false, because generation is synchronous. Kept for web parity.
isCreatingbooleanInsert in progress.
errorError | nullInsert error.

Differences from web

  • Target fields come from the lightweight useDocyrusDataSourceFields schema hook instead of useDocyrusDataViewSelect.
  • The preview step exports CSV, Excel, JSON and Markdown through the share sheet (useDataExport) instead of browser downloads.

Type Exports

TypeDescription
UseDocyrusDummyDataGeneratorWizardOptionsHook options.
UseDocyrusDummyDataGeneratorWizardResultHook result.

The generator types (DummyStrategyMap, DummyGenerationResult, DummyUserOption, DummyRelationOption, …) are exported from dummy-data-generator.

On this page