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

207
Visualizações
How to pass two parameters to custom event handler in React?

I am using Ant design and they have a component called Switch, Switch have a custom event handler

import "./styles.css";
import "antd/dist/antd.css";
import { Switch } from "antd";
import { useState } from "react";

export default function App() {
  const [status, setStatus] = useState(true);
  const handleChange = (e) => {
    // e is a boolean variable, true or false
    console.log(e);
    setStatus(e);
  };
  return (
    <div className="App">
      <h1>Hello CodeSandbox</h1>
      <h2>Start editing to see some magic happen!</h2>
      <Switch checked={status} onChange={handleChange}></Switch>
    </div>
  );
}

and I have so much of question about that kind of syntax

  1. Does
onChange={handleChange}

is equivalent with

onChange={(e) => handleChange(e)}
  1. If for some reason, I can only write
onChange={handleChange}

how can I pass the real event handler to handleChange to do some stopPropagation, some thing likes

const handleChange = (e, reale) => {
    reale.stopPropagation()
    setStatus(e);
  };

Simple codesandbox to understand what I said.

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

0

Does
onChange={handleChange}
is equivalent with
onChange={(e) => handleChange(e)}

They're equivalent if and only if the function receives one argument. But for ant design switches, the onChange actually passes in two parameters: the new value, and the event object. So if you want to create a new function and then call handleChange in that function, you'll probably want to pass both parameters through:

onChange={(value, e) => handleChange(value, e)}
about 4 years ago · Juan Pablo Isaza Relatório

0

You can write thing something like

onChange={(e) => handleChange(e, reale)}
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