@veltdev/react 4.5.0-beta.8 → 4.5.0-beta.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/cjs/index.js CHANGED
@@ -140,7 +140,7 @@ var loadVelt = function (callback, version, staging, develop, proxyDomain) {
140
140
  }
141
141
  };
142
142
 
143
- var VELT_SDK_VERSION = '4.5.0-beta.8';
143
+ var VELT_SDK_VERSION = '4.5.0-beta.9';
144
144
  var VELT_SDK_INIT_EVENT = 'onVeltInit';
145
145
  var VELT_TAB_ID = 'veltTabId';
146
146
 
@@ -6546,6 +6546,41 @@ function usePresenceUsers() {
6546
6546
  }, [presenceElement]);
6547
6547
  return data;
6548
6548
  }
6549
+ function usePresenceData(query) {
6550
+ var presenceElement = usePresenceUtils();
6551
+ var _a = React.useState({ data: null }), data = _a[0], setData = _a[1];
6552
+ var subscriptionRef = React.useRef();
6553
+ // Memoize the inputs
6554
+ var memoizedData = React.useMemo(function () {
6555
+ return query;
6556
+ }, [JSON.stringify(query)]);
6557
+ React.useEffect(function () {
6558
+ if (!(presenceElement === null || presenceElement === void 0 ? void 0 : presenceElement.getData))
6559
+ return;
6560
+ // Unsubscribe from the previous subscription if it exists
6561
+ if (subscriptionRef.current) {
6562
+ subscriptionRef.current.unsubscribe();
6563
+ }
6564
+ var subscription = presenceElement.getData(memoizedData)
6565
+ .subscribe(function (res) {
6566
+ if (res) {
6567
+ setData(res);
6568
+ }
6569
+ else {
6570
+ setData({ data: null });
6571
+ }
6572
+ });
6573
+ // Store the new subscription
6574
+ subscriptionRef.current = subscription;
6575
+ // Cleanup function
6576
+ return function () {
6577
+ if (subscriptionRef.current) {
6578
+ subscriptionRef.current.unsubscribe();
6579
+ }
6580
+ };
6581
+ }, [presenceElement === null || presenceElement === void 0 ? void 0 : presenceElement.getData, memoizedData]);
6582
+ return data;
6583
+ }
6549
6584
 
6550
6585
  function usePresenceEventCallback(action) {
6551
6586
  var presenceElement = usePresenceUtils();
@@ -7215,6 +7250,7 @@ exports.useLiveStateSyncEventCallback = useLiveStateSyncEventCallback;
7215
7250
  exports.useLiveStateSyncUtils = useLiveStateSyncUtils;
7216
7251
  exports.useNotificationUtils = useNotificationUtils;
7217
7252
  exports.useNotificationsData = useNotificationsData;
7253
+ exports.usePresenceData = usePresenceData;
7218
7254
  exports.usePresenceEventCallback = usePresenceEventCallback;
7219
7255
  exports.usePresenceUsers = usePresenceUsers;
7220
7256
  exports.usePresenceUtils = usePresenceUtils;