on f660f7b help sign in
bridge/src/store/pointCache.js
28 lines 696 B history raw
1import React, { createContext, forwardRef, useContext } from 'react';
3import usePointStore from './lib/usePointStore';
5export const PointCacheContext = createContext(null);
7export function PointCacheProvider({ children }) {
8 const cache = usePointStore();
10 return (
11 <PointCacheContext.Provider value={cache}>
12 {children}
13 </PointCacheContext.Provider>
14 );
17// Hook version
18export function usePointCache() {
19 return useContext(PointCacheContext);
22// HOC version
23export const withPointCache = Component =>
24 forwardRef((props, ref) => (
25 <PointCacheContext.Consumer>
26 {cache => <Component ref={ref} {...cache} {...props} />}
27 </PointCacheContext.Consumer>
28 ));