UNPKG

telefunc

Version:

Remote functions. Instead of API.

15 lines (14 loc) 679 B
export { useTelefuncContext }; export { TelefuncSSR }; import { createContext, useContext, createElement } from 'react'; import { assertUsage, isObject } from '../utils.js'; const TelefuncReactContext = createContext(null); function TelefuncSSR({ context, children, }) { assertUsage(context === undefined || isObject(context), '[<TelefuncSSR context={context}/>] context should be an object'); const { Provider } = TelefuncReactContext; return createElement(Provider, { value: context !== null && context !== void 0 ? context : null, children: children }); } function useTelefuncContext() { const context = useContext(TelefuncReactContext); return context; }