Answers for "Passing functions as Props in react"

0

Passing functions as Props in react

const Banner = props => {
  const name = props.name
  return (
    <div>
      <p>Hello {name}</p>
      <button onClick={props.clickHandler}>Click Me</button>
    </div>
  )
}

function App() {
  const showAlert = () => {
    alert("Welcome!")
  }
  return (
    <div>
      <Banner name="Ranjeet" clickHandler={showAlert} />
    </div>
  )
}

export default App
Posted by: Guest on April-10-2022

Code answers related to "Passing functions as Props in react"

Code answers related to "Javascript"

Browse Popular Code Answers by Language