Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

175
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda