2

I'm working on a web part using SPFx with React framework, the presentation layer in on a file called Refiner.tsx, while on the other hand I have my logic on a another file called RefinerWebPart.ts.

How do I get a "global" (for the lack of better term) to be accessible on both modules?

Mr. Dr. Sushi
  • 469
  • 8
  • 22

1 Answers1

1

During the setup of the component (tsx) you can pass props into it, you can move your logic to another class and pass parameters to the method when you call it. You shouldn't really need a global variable. If you can't access something from outside the component write a method inside it. If you need to call this method from an external class you can pass 'this' (the current component) as a parameter.

There is a concept of a global variable if you want to read up on it here (https://learn.microsoft.com/en-us/sharepoint/dev/spfx/web-parts/guidance/share-data-between-web-parts#store-the-retrieved-data-in-a-globally-scoped-variable) but you shouldn't need it in your case while you can use props and state

Hope this clarifies things

Connor Dickson
  • 770
  • 3
  • 12