import * as React from 'react' ; import { createContext , ReactNode , useContext } from 'react' ; import { Record } from '../types' ; example export const RecordContext = createContext < Record | Omit < Record , 'id' > > ( undefined ) ; export const RecordContextProvider = < RecordType extends Record | Omit < Record , 'id' > = Record > ( { children , value , } ) => ( < RecordContext . Provider value = { value } > { children } < /RecordContext.Provider>); RecordContext . displayName = 'RecordContext' ; export interface RecordContextOptions < RecordType > { children : ReactNode ; value ? : RecordType ; } example example returns { Record } export const useRecordContext = < RecordType extends Record | Omit < Record , 'id' > = Record > ( props ? ) : RecordType => { const context = useContext < RecordType > ( RecordContext ) ; return ( props && props . record ) || context ; } ; export interface UseRecordContextParams < RecordType extends Record | Omit < Record , 'id' > = Record > { record ? : RecordType ; [ key ] : any ; }