0

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

Dev
  • 2,428
  • 2
  • 14
  • 15
  • I remember a related issue [is discussed in Github](https://github.com/microsoftgraph/microsoft-graph-toolkit/issues/865); see if it fits your scenario. – Dev Jan 13 '21 at 07:08
  • The microsoft graph toolkit recently introduced a [caching](https://learn.microsoft.com/en-us/graph/toolkit/customize-components/cache) feature. see if the example will help you with your implementation for each get resource. – Nic Vogt Jan 13 '21 at 22:29
  • I have a polling enabled for caching is not respected with it.. – sohil bhalla Jan 14 '21 at 10:00

0 Answers0