MCPcopy Create free account
hub / github.com/dailydotdev/apps / withPostById

Function withPostById

packages/shared/src/components/post/withPostById.tsx:18–52  ·  view source on GitHub ↗
(
  WrappedComponent: WrappedComponentType<Props, LayoutProps>,
)

Source from the content-addressed store, hash-verified

16};
17
18export const withPostById = <Props, LayoutProps = unknown>(
19 WrappedComponent: WrappedComponentType<Props, LayoutProps>,
20): WrappedComponentType<Props, LayoutProps> => {
21 const WithPostById = (props: Props & { post?: Post }): ReactElement => {
22 const { post: initialPost } = props;
23
24 const { post: loadedPost } = usePostById({
25 id: initialPost?.id,
26 });
27 const post = loadedPost ?? initialPost;
28
29 if (!post?.id) {
30 return null;
31 }
32
33 // Important to maintain the feed meta if it exists
34 if (!post?.feedMeta && initialPost?.feedMeta) {
35 post.feedMeta = initialPost.feedMeta;
36 }
37
38 return <WrappedComponent {...props} post={post} />;
39 };
40
41 WithPostById.displayName = 'WithPostById';
42
43 if (WrappedComponent.getLayout) {
44 WithPostById.getLayout = WrappedComponent.getLayout;
45 }
46
47 if (WrappedComponent.layoutProps) {
48 WithPostById.layoutProps = WrappedComponent.layoutProps;
49 }
50
51 return WithPostById;
52};

Calls

no outgoing calls

Tested by

no test coverage detected