evently-react
Version:
A Hook-Based Framework for Event-Driven React Apps
15 lines (14 loc) • 684 B
JavaScript
import { jsx as _jsx } from "react/jsx-runtime";
import { useMemo } from 'react';
import { EventBus } from '../core';
import { CacheEnabled, CacheTTL } from '../constants';
import { EventContext } from './EventContext';
const defaultConfig = {
cacheTTL: CacheTTL,
cacheEnabled: CacheEnabled,
};
export const EventProvider = ({ children, cacheTTL = defaultConfig.cacheTTL, cacheEnabled = defaultConfig.cacheEnabled, }) => {
// Memoize the EventBus instance to ensure a single instance
const eventBus = useMemo(() => new EventBus({ cacheEnabled, cacheTTL }), [cacheEnabled, cacheTTL]);
return _jsx(EventContext.Provider, { value: eventBus, children: children });
};