import { useEffect, useState } from 'react';
import { getPostTopic, PostRepository, subscribeTopic } from '@amityco/ts-sdk-react-native';
export const usePostSubscription = postId => {
  const [subscribedPost, setSubscribedPost] = useState(null);
  useEffect(() => {
    let unsubscribe;
    if (postId) {
      unsubscribe = PostRepository.getPost(postId, ({
        data
      }) => {
        setSubscribedPost(data);
      });
    }
    return () => {
      unsubscribe && unsubscribe();
    };
  }, [postId]);
  useEffect(() => {
    let unsubscribe;
    if (subscribedPost) {
      unsubscribe = subscribeTopic(getPostTopic(subscribedPost));
    }
    return () => {
      unsubscribe && unsubscribe();
    };
  }, [subscribedPost]);
  return {
    subscribedPost
  };
};
//# sourceMappingURL=usePostSubscription.js.map