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

173
Views
How to pass a value from one class to the main one in React

Lets say I have these two files: App.js (the file that actually runs the program)

const App = () => {
    const [variable1, setVariable1] = useState(0);
    return (
    <NewFile />
    );
}
export default App;

NewFile.js

const NewFile = () => {
    const [partText, setPartText] = useState("");
    const [wholeText, setWholeText] = useState("");
    if (partText != "")
    {
       setWholeText(partText);
    }
 return (
    {wholeText}
    );
}
export default NewFile;

Now, here comes my question. How can I set "variable1" to be equal to "wholeText"? The most logical solution would be: setVariable1(NewFile.wholeText) and obviously it doesn't work like that. I have seen some solutions with props but from what I understood I can only pass the value from (in this case) App.js to NewFile.js because I am calling NewFile.js in App.js.

I might have understood props wrongly and there might be a simple way to do the opposite, but I really can't think of anything else for now.

almost 4 years ago · Santiago Trujillo
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!