1

I am using Fabric React with SPFx. I want to use one component public method to another component. How can be possible to reuse method?

My Parent Component:

export class PanelSmallRightExample2 extends React.Component<
{
...
  public _onShowPanel1()
  {
    alert("other");
  }; 
}

Accessing Parent method into child:

import { PanelSmallRightExample2 } from './PanelExample_1';

let panelExample = React.createElement(PanelSmallRightExample2);

now, by "panelExample" object not accessible my child method.

Please help me.

2

You are missing the 'static' keyword in your class definition. I have tried below in my test environment and it works superfine :

export class PanelSmallRightExample2 {
    public static _string = ""
    public static _onShowPanel1() {
        alert("other");
    };
}

and using them in another web part TS file as:

import {PanelSmallRightExample2} from './abc';

let obj1 = PanelSmallRightExample2._string;
let obj2 = PanelSmallRightExample2._onShowPanel1();
  • @Prashant, Did this resolve your issue? – DvG Jul 3 '18 at 6:07
  • 1
    Ok I will try. And provide you feedback for the same. – Prashant Shah Jul 3 '18 at 11:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.