I have a List component with has a list item template as a react component calling Graph Api using Graph Api toolkit react component also the template has component as show below.
List Component
<List
indicateLoading={true}
dataSource={listDataSource}
height="100%"
selectionMode="single"
grouped={true}
collapsibleGroups={true}
groupRender={GroupTemplate} searchEnabled={true}
onGroupRendered={groupRendered} itemComponent={**LastMessageDetails**} searchExpr={["key"]} onItemClick={messageSelected}
activeStateEnabled={false} focusStateEnabled={false} hoverStateEnabled={false}
/>
LastMessageDetails
<div>
<Get maxPages= {1} version="beta" resource={"teams/"+Constants.TeamsID+"/channels/"+ props["data"].ChannelId + "/messages/" + props["data"].MessageId + "/replies?$top=1"}>
<LastMessageItem template="value"/>
<LoadingTemplate template="loading"/>
</Get>
</div>
LastMessageItem
export const LastMessageItem = (props: MgtTemplateProps) => {
TemplateHelper.setBindingSyntax('[[', ']]');
const [content, setContent] = React.useState("");
React.useEffect(() => {
const object = props.dataContext;
setContent(object.body.content);
}, [])
return (<div className="">
<Person userId={props.dataContext.from.user.id} showPresence={true} personCardInteraction={1} view={PersonViewType.oneline}></Person>
<div className="conversationMessage" data-props="innerHTML:formatBodyContent(body.content)">
{formatBodyContent(content)}
</div></div>);
}
When the list component is rendered or re-rendered the Graph calls are fired again even if the props or the resource is not changed at all. Is there a way we can protect the graph calls to happen again and again when the parent list component is rendered.
Re-Rendering of child components when parent list component is re-rendered