Skip to main content

useCreatePost

Introduction

The useCreatePost hook is a custom hook that provides functionality to create a new post in the feed. It handles the state and logics and functions required to create or edit a post. This hook simplifies the process of creating custom UI for post creation and editing.

The useCreatePost hook returns the following properties.

PropertyTypeDescription
postTextstring | nullThe text content of the post.
setPostText(text: string) => voidFunction to set the text content of the post.
questionstring | nullThe question content of the post.
setQuestionText(text: string) => voidFunction to set the question content of the post.
mediaListFile[]List of media files attached to the post.
addMediaItem(event: React.ChangeEvent<HTMLInputElement>) => voidFunction to add a media item to the post.
removeMedia(index: number) => voidFunction to remove a media item from the post by index.
clearMedia() => voidFunction to clear all media items from the post.
mediaUploadModeLMFeedCreatePostMediaUploadModeThe mode of media upload for the post.
changeMediaUploadMode(mode: LMFeedCreatePostMediaUploadMode) => voidFunction to change the media upload mode.
textFieldRefMutableRefObject<HTMLDivElement | null>Reference to the text field element.
containerRefMutableRefObject<HTMLDivElement | null>Reference to the container element.
postFeed() => Promise<void>Function to post the feed.
editPost() => Promise<void>Function to edit the post.
ogTagOgTag | nullOpen Graph tag information for the post.
openCreatePostDialogbooleanFlag indicating if the create post dialog is open.
setOpenCreatePostDialogReact.Dispatch<boolean>Function to set the open state of the create post dialog.
temporaryPostPost | nullTemporary post data.
clearPollFunction() => voidFunction to clear the poll.
editPollFunction() => voidFunction to edit the poll.
selectedTopicIdsstring[]List of selected topic IDs for the post.
setSelectedTopicIdsReact.Dispatch<string[]>Function to set the selected topic IDs.
preSelectedTopicsTopic[]List of preselected topics for the post.
setPreSelectedTopicsReact.Dispatch<Topic[]>Function to set the preselected topics.
showOGTagViewContainerbooleanFlag indicating if the OG tag view container is shown.
closeOGTagContainer() => voidFunction to close the OG tag container.
removeThumbnailReel() => voidFunction to remove the thumbnail reel.
removeAddReel() => voidFunction to remove the added reel.
createPostComponentClickCustomCallbackComponentDelegatorListener | undefinedOptional custom callback for component click events.
addThumbnailReel(event: React.ChangeEvent<HTMLInputElement>) => voidFunction to add a thumbnail reel.
addReel(event: React.ChangeEvent<HTMLInputElement>) => voidFunction to add a reel.
tempReelFile[]List of temporary reel files.
tempReelThumbnailFile[]List of temporary reel thumbnail files.
isAnonymousPostbooleanFlag indicating if the post is anonymous.
changeAnonymousPostStatus() => voidFunction to change the anonymous post status.
openCreatePollDialogbooleanFlag indicating if the create poll dialog is open.
setOpenCreatePollDialogReact.Dispatch<boolean>Function to set the open state of the create poll dialog.
pollOptionsPollOption[]List of poll options.
addPollOptionZeroArgVoidReturnsFunction to add a poll option.
updatePollOptionTwoArgVoidReturns<string, number>Function to update a poll option.
removePollOptionOneArgVoidReturns<number>Function to remove a poll option.
changePollTextOneArgVoidReturns<React.ChangeEvent<HTMLTextAreaElement>>Function to change the poll text.
pollTextstringThe text content of the poll.
updatePollExpirationDateOneArgVoidReturns<number | null>Function to update the poll expiration date.
pollExpirationDatenumber | nullThe expiration date of the poll.
advancedOptionsAdvancedPollOptionsThe advanced options for the poll.
validatePollbooleanFlag indicating if the poll validation is enabled.
previewPollbooleanFlag indicating if the poll preview is shown.
setPreviewPollReact.Dispatch<boolean>Function to set the poll preview state.
updateAdvancedOptionsOneArgVoidReturns &lt;React.ChangeEvent<HTMLInputElement> &#124; SelectChangeEvent&lt;number&gt; &gt;Function to update advanced poll options.
pollExpiryTimeClickFunction() => voidFunction to handle poll expiry time click event.

Example

For example implementation, checkout here