UNPKG

stream-chat-react-native-core

Version:

The official React Native and Expo components for Stream Chat, a service for building chat applications

30 lines 969 B
Object.defineProperty(exports, "__esModule", { value: true }); exports.useSelectedChannelState = useSelectedChannelState; var _react = require("react"); var _shim = require("use-sync-external-store/shim"); var noop = () => {}; function useSelectedChannelState({ channel, selector, stateChangeEventKeys = ['all'] }) { var subscribe = (0, _react.useCallback)(onStoreChange => { if (!channel) { return noop; } var subscriptions = stateChangeEventKeys.map(et => channel.on(et, () => { onStoreChange(selector(channel)); })); return () => subscriptions.forEach(subscription => subscription.unsubscribe()); }, [channel, selector, stateChangeEventKeys]); var getSnapshot = (0, _react.useCallback)(() => { if (!channel) { return undefined; } return selector(channel); }, [channel, selector]); return (0, _shim.useSyncExternalStore)(subscribe, getSnapshot); } //# sourceMappingURL=useSelectedChannelState.js.map