Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

151
Views
How to export a variable to another react functional component?

I am creating this react app in which I want to export a variable to another react functional component. I am also facing an issue since when a user clicks on a button, only then will the variable contain value or else it is undefined and exporting an undefined variable is not possible. So I was hoping that there is a way I can export the variable only when it contains a value. Thanks in advance to anyone who has helped!

PS: I am a Beginner :)

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

if this variable is defined inside your the function of your component you can't export it


const canExport = 'yes we can'

const App = () => {
    const iAmImpossibleToExport = []

    return <div>The application</div>
}
export { canExport }

export default App 

If you want to pass variables to other components, you can use props, context, redux.... but it's more advanced topics (redux and context) and tools that should be manipulated and used carefully. You probably juste need state and props at your level.

Good luck with you journey into React

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!