/
githubmirror
/
tldraw
Обзор
Документация
Войти
/
githubmirror
/
tldraw
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
packages/editor/src/lib/hooks/useTLStore.ts
34 строки
895 B
alex
Fix snapshots prop (#4233)
20 июл 2024, 15:50
Не верифицирован
20 июл 2024, 15:50
87a3c0b
Код
Авторство
О чём код?
import { areObjectsShallowEqual } from '@tldraw/utils' import { useState } from 'react' import { TLStoreOptions, TLStoreSchemaOptions, createTLSchemaFromUtils, createTLStore, } from '../config/createTLStore' /** @public */ export function useTLStore(opts: TLStoreOptions) { const [current, setCurrent] = useState(() => ({ store: createTLStore(opts), opts })) if (!areObjectsShallowEqual(current.opts, opts)) { const next = { store: createTLStore(opts), opts } setCurrent(next) return next.store } return current.store } /** @public */ export function useTLSchemaFromUtils(opts: TLStoreSchemaOptions) { const [current, setCurrent] = useState(() => ({ opts, schema: createTLSchemaFromUtils(opts) })) if (!areObjectsShallowEqual(current.opts, opts)) { const next = createTLSchemaFromUtils(opts) setCurrent({ opts, schema: next }) return next } return current.schema }