Forum Discussion

john john's avatar
john john
Iron Contributor
Nov 06, 2021
Solved

SPFX web part to add Text and show it inside a Popup when clicking on a button

I am trying to achieve this using SPFX web part:- The web part will render a Button and has a text field inside its settings. The user add the Web Part >> edit it >> enter the text inside the ...
  • Don Kirkham's avatar
    Nov 08, 2021

    john john 

    You need to pass the text to display variable (which looks like the description property in the property panel) into the MyPortal React element.  It is already being passed into the ReactPortal React component as part of the IReactPortalProps object, so you just need to pass that through to MyPortal as an attribute.

     

    First, change line 4 in MyPortal.tsx to 

     

    const Myportal = (textToDisplay: string) => {

     

     

    To use the parameter, place it in the return object. It looks like you want to replace line 49 in MyPortal.tsx with

     

    {textToDisplay}

     

     

    To pass the description property into MyPortal, replace line 8 in ReactPortal.tsx with 

     

    <Myportal textToDisplay={props.description}/>

     

     

    I hope this help show how to pass properties into React function components. If this helps, please consider marking this as the approved solution.

     

    Good luck,

    Don Kirkham

Resources