How to send custom JSON data inside a post
The LikeMinds Feed SDK allow developers to send custom JSON data inside a post. Developers can use this to send additional use-cases depending on their use-cases.
Sending the Custom Data with the Post
To send additional data with the post, you will need to override the default postFeed
function. The LikeMinds Feed SDK allows you to override certain SDK functions on top of the default one.
To override you can pass the new function as a prop to LMFeed
. The following steps explain on how you can achieve this
Steps to send Custom JSON data
Step 1 - Create a callback function
Create a new function postCustomAction
, which accepts an argument store
. The store
contains information including defaultActions
declared inside the host hook. Now destructure the defaultActions
and postFeed
to get the default postFeed
action.
You can send custom data by passing an array of JSON Objects as an argument to the default action.
const customPostAction = async (store) => {
const {
defaultActions: { postFeed },
} = store;
const customJSONData = {
"Custom Key": "Custom Value",
};
postFeed([customJSONData]);
};
Step 2 - Pass your custom callback to LMFeed
After creating your custom callback pass this callback to LMFeed
.
// Other SDK Components
<LMFeed
// Other SDK props
PostCreationCustomCallbacks={{
postFeedCustomAction: async (store) => {
const {
defaultActions: { postFeed },
} = store;
// This will give you an instance of the new text field we've added.
const ctaInputField: HTMLInputElement = document.getElementById(
"cta-link-input"
) as HTMLInputElement;
postFeed([
{
cta: ctaInputField.value,
},
]);
},
}}
></LMFeed>
Step 3 - Run the project.
Start your project by running npm run dev
or npm start
in your terminal, and create a post.