import React, { memo } from 'react' import { createContextualProps } from './createContextualProps' /** * Useful for having a scoped id that nests as it goes downwards * See useUserState/useAppState for good examples using it */ type ScopedStateProps = { id: string } const Context = createContextualProps({ id: '', }) export const useScopedStateId = () => { const val = Context.useProps() return (val && val.id) || '' } export const ScopeState = memo((props: ScopedStateProps & { children?: any }) => { const existing = Context.useProps() return ( {props.children} ) })