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

273
Visualizações
I am learning React and it seems I cannot define a function component while inside a class component, is this true or am I doing something wrong?

As the title says, trying to declare a component within my class, however, getting an Undefined error. Can I not do this or am I doing it wrong? As I said, I'm new to React so any bit of info helps. The overall goal is to create a form but I'm trying to only make certain options pop depending on what the previous options are. If the code is too much let me know, I'll trim it down to what's import but I figured I'd provide the whole thing cause it's not that long.

import React, {useState, useMemo} from 'react';
import ReactDOM from 'react-dom/client';
import countryList from 'react-select-country-list';
import './index.css';
//import App from './App';


class StartForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {};

    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
    this.options = countryList().getData();
  }

  handleChange(event) {
    this.setState({[event.target.name]: event.target.value});
    //alert('Your favorite flavor is: ' + this.state.value);
    console.log(this.state.accType);
  }

  handleSubmit(event) {
    //alert('Your favorite flavor is: ' + this.state.value);
    //event.preventDefault();
  }

//------------------- THIS COMPONENT
  CustomOptions(props) {
    return(
        <label>
          <input type="checkbox" id="acss_debit_payments" name="acss_debit_payments" value={this.value.acss_debit_payments} onChange={this.handleChange} />Paneer
        </label>
      );
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          Select Account Type:
          <select name="accType" value={this.state.accType} onChange={this.handleChange}>
            <option value="custom">Custom</option>
            <option value="express">Express</option>
            <option value="standard">Standard</option>
          </select>
        </label>
        <br/>
        <label>
          Select Country Code(Optional):
          <select name="country" options={this.options} value={this.state.country} onChange={this.handleChange}/>
        </label>
        <br/>
        <label>
          Email:
          <input type="text" name="email" value={this.state.email} onChange={this.handleChange} />
        </label>
        <input type="submit" value="Submit" />

        {this.state.accType == "custom" &&
          <CustomOptions />
      }

      </form>
    );
  }
}


const root = ReactDOM.createRoot(document.getElementById('root'));
root.render(
  <React.StrictMode>
    <StartForm/>
  </React.StrictMode>
);


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

0

To call CustomOptions you need to reference the current instance with this:

<this.CustomOptions />

Example: https://codesandbox.io/s/happy-swartz-hsm6ng?file=%2Fsrc%2FApp.js

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