Skip to main content
Participant
May 9, 2023 2:20 PM UTC
Answered

How do I Import another JSX file to My Main JSX File

Hey, So I am trying to seprate code for readablity. I have two files so far. I am trying to import the file into the main file. I tried using #include but i got an error saying I could not use it outside a class. I saw online another example //@include but that does not work. It just comments out the import. What is the proper way of importing a file ?

This topic is closed to new replies. Start a new post to keep the conversation going.
rob day
rob dayCorrect answer
Community Expert
May 9, 2023 3:08 PM UTC

This example works for me. Create a file named HelloWorld.jsxinc with a function you want to run:

 

/**
* Discription 
* @ param a string
* @ return string 
*/

function helloWorld(s){
  return "From Hello World: " + s
}

 

Save the .jsxinc file in the same directory with the script that will include it—here is an example script that incudes the .jsxinc file:

 

#include "HelloWorld.jsxinc"
alert(helloWorld("Hi There!"))

 

The include sample run:

 

 

5 replies

Charu Rajput
Community Expert
Community Expert
May 9, 2023 3:34 PM UTC

@Victor29751988fsbx , if solution by @rob day does not work, could you post your separate code file, so that we can help?

Translate
Best regards
Participant
May 9, 2023 6:07 PM UTC

Thanks they have been really helpful

Translate
rob day
Community Expert
rob dayCommunity ExpertCorrect answer
Community Expert
May 9, 2023 3:08 PM UTC

This example works for me. Create a file named HelloWorld.jsxinc with a function you want to run:

 

/**
* Discription 
* @ param a string
* @ return string 
*/

function helloWorld(s){
  return "From Hello World: " + s
}

 

Save the .jsxinc file in the same directory with the script that will include it—here is an example script that incudes the .jsxinc file:

 

#include "HelloWorld.jsxinc"
alert(helloWorld("Hi There!"))

 

The include sample run:

 

 

Translate
rob day
Community Expert
Community Expert
May 9, 2023 2:43 PM UTC
Inspiring
Dec 3, 2024 11:28 AM UTC

thank you

Translate