TinyBase logoTinyBase β

toValuesSchema

The toValuesSchema method converts a mapping of Yup schemas into a TinyBase ValuesSchema.

toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema
TypeDescription
schemas{[valueId: string]: any}

A mapping of value IDs to Yup schemas.

returnsValuesSchema

A TinyBase ValuesSchema.

This method extracts basic type information (string, number, boolean), string enums, default values, and nullable flags from Yup schemas.

Example

This example converts Yup schemas to TinyBase values.

import {createStore} from 'tinybase';
import {createYupSchematizer} from 'tinybase/schematizers/schematizer-yup';
import {boolean, number} from 'yup';

const schematizer = createYupSchematizer();

const valuesSchema = schematizer.toValuesSchema({
  open: boolean().default(true),
  employees: number(),
});

const store = createStore().setValuesSchema(valuesSchema);
console.log(store.getValues());
// -> {open: true}

Since

v7.1.0