Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

Passing a state as a prop in react

import { useState } from "react"

const Banner = props => {
  const name = props.name
  return (
    <div>
      <p>
        {props.greeting} {name}
      </p>
    </div>
  )
}

function App() {
  const [greeting, setGreeting] = useState("Hello")
  return (
    <div>
      <Banner name="Ranjeet" greeting={greeting} />
    </div>
  )
}

export default App
Source by softhunt.net #
 
PREVIOUS NEXT
Tagged: #Passing #state #prop #react
ADD COMMENT
Topic
Name
8+1 =