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

134
Visualizações
add/remove elements of checkbox from the array of state object in React

When user click on the checkbox item it should be added to array. When unchecked it should be removed from array list. conditions: Maintain the array in the state object which contains the employmentType of the checked checkbox input elements 1.Whenever the employment type input checkbox is checked, that respective employment type id should be present in the array 2.And whenever the employment type input checkbox is unchecked, that respective employment type id should be removed from the array 3.Form the string using join() and use that string as a query parameter in jobsApiUrl code:

const employmentTypesList = [
  {label: 'Full Time',
    employmentTypeId: 'FULLTIME',
  },
  {
    label: 'Part Time',
    employmentTypeId: 'PARTTIME',
  },
  {
    label: 'Freelance',
    employmentTypeId: 'FREELANCE',
  },
  {
    label: 'Internship',
    employmentTypeId: 'INTERNSHIP',
  },
]

class Jobs extends Component {
  state = {
    apiStatus: apiConstantStatus.initial,
    jobsList: [],
    searchInput: '',
    activeEmploymentId: '',
    activeSalaryId: '',
    employmentTypeListId: [], 
  }
  
  componentDidMount() {
    this.getJobs()
  }

  getJobs = async () => {
    this.setState({apiStatus: apiConstantStatus.inProgress})
    const jwtToken = Cookies.get('jwt_token')
    const {employmentTypeListId, activeSalaryId, searchInput} = this.state

    // Need update Here
    const employmentType = employmentTypeListId.join(',')

    const apiUrl = `https://apis.ccbp.in/jobs? 
    employment_type=${employmentType}&minimum_package=${activeSalaryId}&search=${searchInput}`
    const options = {
      headers: {
        Authorization: `Bearer ${jwtToken}`,
      },
      method: 'GET',
    }
}
}
export default Jobs

//render method

onChangeEmployTypesIds = event => {

    const {employmentTypeListId} = this.state
    const isChecked = event.target.checked
    console.log(isChecked)
    // add values to array
    if (isChecked) {
      this.setState({
        employmentTypeListId: [...employmentTypeListId, event.target.value],
      })
    } else {

      // remove item from array

      const filtered = employmentTypeListId.filter(
        eachItem => eachItem !== event.target.value,
      )
      this.setState({employmentTypeListId: filtered})
    }
}
renderEmploymentTypesList = () => {

const {activeEmploymentId} = this.state

    return employmentTypesList.map(empType => (
      <li key={empType.employmentTypeId} >
        <input
          type="checkbox"
          className="checkbox-input"
          id="emp"
          value={activeEmploymentId}
          onChange={this.onChangeEmployTypesIds}
        />
        <label htmlFor="emp" className="label-name" value="label">
          {empType.label}
        </label>
      </li>
    ))
}
about 4 years ago · Juan Pablo Isaza
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