Skip to content

Commit 8bc691b

Browse files
authored
Update react package to wc-react 0.5.0 and added ref support (#1137)
1 parent a232284 commit 8bc691b

File tree

4 files changed

+16
-6
lines changed

4 files changed

+16
-6
lines changed

packages/mgt-react/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"@microsoft/mgt-element": "*",
3636
"@microsoft/microsoft-graph-types": "^1.36.0",
3737
"@microsoft/microsoft-graph-types-beta": "^0.7.0-preview",
38-
"wc-react": "^0.4.0"
38+
"wc-react": "^0.5.0"
3939
},
4040
"publishConfig": {
4141
"access": "public"

packages/mgt-react/src/Mgt.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,8 @@ export class Mgt extends Wc {
142142
* @returns React component
143143
*/
144144
export const wrapMgt = <T = WcProps>(tag: string) => {
145-
const component: React.FC<T & React.HTMLAttributes<any>> = (props: T) =>
146-
React.createElement(Mgt, { wcType: tag, ...props });
145+
const component: React.ForwardRefExoticComponent<
146+
React.PropsWithoutRef<T & React.HTMLAttributes<any>> & React.RefAttributes<unknown>
147+
> = React.forwardRef((props: T, ref) => React.createElement(Mgt, { wcType: tag, innerRef: ref, ...props }));
147148
return component;
148149
};

samples/react-app/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@
77
"@microsoft/mgt-react": "*",
88
"@microsoft/mgt-msal-provider": "*",
99
"@webcomponents/webcomponentsjs": "2.2.10",
10-
"react": "^16.8.5",
10+
"react": "^17.0.1",
1111
"react-app-polyfill": "1.0.1",
12-
"react-dom": "^16.8.5",
12+
"react-dom": "^17.0.1",
1313
"react-scripts": "^3.0.0"
1414
},
1515
"scripts": {

samples/react-app/src/App.tsx

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React, { Component } from 'react';
1+
import React, { Component, useRef } from 'react';
22
import {
33
Login,
44
Agenda,
@@ -10,6 +10,7 @@ import {
1010
Get
1111
} from '@microsoft/mgt-react';
1212
import * as MicrosoftGraph from '@microsoft/microsoft-graph-types';
13+
import { MgtPerson } from '@microsoft/mgt-components';
1314

1415
class App extends Component {
1516
handleTemplateRendered = (e: Event) => {
@@ -65,13 +66,21 @@ const MyTemplate = (props: MgtTemplateProps) => {
6566
const MyMessage = (props: MgtTemplateProps) => {
6667
const message = props.dataContext as MicrosoftGraph.Message;
6768

69+
const personRef = useRef<MgtPerson>();
70+
71+
const handlePersonClick = () => {
72+
console.log(personRef.current);
73+
};
74+
6875
return (
6976
<div>
7077
<b>Subject:</b>
7178
{message.subject}
7279
<div>
7380
<b>From:</b>
7481
<Person
82+
ref={personRef}
83+
onClick={handlePersonClick}
7584
personQuery={message.from?.emailAddress?.address || ''}
7685
fallbackDetails={{ mail: message.from?.emailAddress?.address, displayName: message.from?.emailAddress?.name }}
7786
view={PersonViewType.oneline}

0 commit comments

Comments
 (0)