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