import React from 'react' import type { Store } from '../state' import { createStore } from '../state' import type { Emitter } from '../events' import { createEmitter } from '../events' import type { GridFullApi } from '../api' import { createApi } from '../api' export type UseGridReturn = Store & { events: Emitter; api: GridFullApi } export function createGrid() { const events = createEmitter() const store = createStore() const api = createApi(store, events) return { ...store, events, api } } export function useGrid() { const gridState = React.useRef(null) if (gridState.current === null) { gridState.current = createGrid() } return gridState.current }