toValuesSchema
The toValuesSchema method converts a mapping of Yup schemas into a TinyBase ValuesSchema.
toValuesSchema(schemas: {[valueId: string]: any}): ValuesSchema| Type | Description | |
|---|---|---|
schemas | {[valueId: string]: any} | A mapping of value IDs to Yup schemas. |
| returns | ValuesSchema | A TinyBase |
This method extracts basic type information (string, number, boolean), string enums, default values, nullable flags, and required 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