Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

163
Vistas
¿Por qué no se vuelve a renderizar useState?

He inicializado un estado basado en una llamada a la base de datos en un componente principal, y cuando lo actualizo, mi componente no se vuelve a procesar. La única razón real por la que elegí implementar el estado aquí es permitir una reproducción automática después de que un usuario decida cambiar su posición presionando el botón. Aquí está mi código

 import React, { useEffect, useState } from "react" import { Button, ButtonGroup, ToggleButton } from "react-bootstrap" import { useQuery, useMutation } from "@apollo/react-hooks" import { QUERY_ME_BASIC } from "../utils/queries" import { UPDATE_POSITION } from "../utils/mutation" function JobSwitchButton() { const { data } = useQuery(QUERY_ME_BASIC) const [updatePosition] = useMutation(UPDATE_POSITION) const [checked, setChecked] = useState(false); let user = data?.me || {} const initialPosition = user.customer ? ("customer") : ("driver") const [position, setPosition] = useState(initialPosition) var driver var customer const handleSubmit = async e => { e.preventDefault() console.log(e.target.value) if (e.target.value === "customer") { customer = true driver = false } else { customer = false driver = true } await updatePosition({ variables: { _id: user._id, driver: driver, customer: customer } }) setPosition(e.target.value) } return ( <> <Button value={user.customer ? ("driver") : ("customer")} onClick={handleSubmit}> {user.customer ? ("change to driver") : ("change to customer")} </Button> </> ) } export default JobSwitchButton

Agradezco cualquier entrada!

about 4 years ago · Juan Pablo Isaza
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda