microsoft / powerbi-client-react

Power BI for React which provides components and services to enabling developers to easily embed Power BI reports into their applications.
MIT License
310 stars 98 forks source link

events map hadler does not update with react context #108

Closed alan9518 closed 7 months ago

alan9518 commented 8 months ago

Im having troubles using the events map handler as mentioned in the docs with react context api

i have this map for the events which works fine, but when i try to read values inside the rendered event those values are never updated, even when the actual values change from the context

this funciton comes from a react context, which returns an array of places ['city1' 'city2'], however every time to read this variable inside the rendered event, is always the same original initial state declared in the context creation, it never updates with the context

const mapFiltersList = getMapFiltersList();
console.log('mapFiltersList', mapFiltersList) //returns ['city1' 'city2']
const eventHandlersMap = new Map([
        [
          "rendered",
          (event: any, report: any) => {
            // here I try to read the values of a mapFilterslist variable 
            but its always an empty array
            onReportRerender();
          },
        ],

        [
          "dataSelected",
          (event: service.ICustomEvent<any>, report: Report) => {

            // here I store the details of the event in a context
            // which works fine i can see the changes in the context every time
          },
        ],

      ])    

here is the return

 return (
      <PowerBIEmbed
        embedConfig={INITIAL_REPORT_CONFIG}
        ref={reportRef}
        eventHandlers={eventsMap}
        cssClassName={`report-style-class ${containerHeightClass}`}
        getEmbeddedComponent={(embedObject) => {
          saveReportState(embedObject as Report);
        }}
      />
  );