The Reactions component renders both a container that displays reactions and a button you can use to add and remove reactions belonging to a particular message. This component works similarly to reactions you might have seen in Slack or WhatsApp. When the user clicks an existing reaction, they will react to the message with the same emoji and the count will increase. If they select the same reaction a second time, their reaction will be removed and the count will decrease.
You can use this alongside other Cord components to build any message layout that you might need. For example, you can use our Thread API to get the thread and messages IDs you need to hook this up to the exact message you want.
import{Reactions, thread }from"@cord-sdk/react";// Adding a Reactions component to the first message of a thread.exportconstExample=()=>{const threadId =useMemo(()=>'thread-'+Date.now(),[]);const threadSummary = thread.useThread(threadId);return(<><p>Add an initial message which you can react to:</p>{threadId &&<Thread threadId={threadId}/>}{threadId && threadSummary?.thread.firstMessage?.id &&(<Reactions threadId={threadId} messageId={threadSummary?.thread.firstMessage.id}/>)}</>);};
An arbitrary string that uniquely identifies a
message. This message ID is for the message you want the reactions to belong to. This message must belong in the thread specified with threadId.
If no valid message ID is set, reactions is rendered in a disabled state.