UNPKG

frontend-hamroun

Version:

A lightweight frontend JavaScript framework with React-like syntax

24 lines (23 loc) 708 B
const contexts = new Map(); export function createContext(defaultValue) { const contextId = Symbol('context'); const Provider = ({ value, children }) => { contexts.set(contextId, value); return children; }; const Consumer = ({ children }) => { const value = contexts.get(contextId) ?? defaultValue; return children(value); }; const context = { Provider, Consumer, displayName: 'Context' }; return context; } export function useContext(context) { // In a real implementation, this would access the context value from the component tree // For now, returning a default value to satisfy TypeScript return {}; }