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

118
Visualizações
How to pass data from class React.Component to jsx file

I have a class with form and I want to pass entered data to next jsx file =>

Here is class ("sender")

import React from 'react'
import Button from './Button';

class Sender extends React.Component {
    constructor() {
        super();
        this.state = {
          imie: '',
        };
        
        this.redirect = this.redirect.bind(this);
        this.handleChange = this.handleChange.bind(this);
      }
      handleChange({ target }) {
        this.setState({
          [target.name]: target.value
        });
      }
      getData(){
        const sendData = [
            {
                name: this.state.name
            }
        ]
      }
    render() {
        return (
                <div className="order-wrapper">
                    <div className="order">
                        <div className="order-box">
                            <label htmlFor="name">Imie: </label>
                            <input 
                            type="text" 
                            name="name" 
                            id="name" 
                            value={ this.state.name }
                            onChange={ this.handleChange } 
                            />
                        </div>
                        <div className="order-box">
                            <Button 
                            type="submit"
                            value="Zamów"
                            className="zamowbtn"
                            onClick={this.redirect}
                            />
                        </div>
                    </div>
                </div>
            </div>
        )
    }
}

export default Sender

From this class I want to send name value which is located in getData() function.

I need that value in .jsx file below and show it in console.log(). How to do it? Please help me:)

import React from 'react'
import Sender from './Sender'

const Finish = () => {
  
  return (
    <div>
      { /* Here i need my 'name' value from Sender Class */ }
    </div>
  )
}

export default Finish
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

If there are in different parts of Application and one is not a parent of second one. You should use Context API for this

about 4 years ago · Juan Pablo Isaza Relatório
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