Answers for "react onclick prop"

0

handling event in jsx

//Event hadling in react
function ActionLink() {
  function handleClick(e) {
    e.preventDefault();
    console.log('The link was clicked.');
  }

  return (
    <a href="#" onClick={handleClick}>
      Click me
    </a>
  );
}
Posted by: Guest on May-01-2020
0

using props in function component for onclick event

const HelloWorld = ({ dispatch }) => {
  const handleClick = useCallback(() => {
    dispatch(something())
  })
  return <button onClick={handleClick} />
}
Posted by: Guest on March-08-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language