Home > front end >  How to pass value and functions from one component to another in function components in React
How to pass value and functions from one component to another in function components in React

Time:10-25

I want to pass the value written in input field to app component and show it in h1 tag

You can refer to this sandbox I have attached. I have already tried passing function as prop but it doesn't help.

Edit bold-boyd-srjrf

CodePudding user response:

You can pass any data as a props in react component. Components and props in React

Example :

function Welcome(props) {
  return <h1>Hello, {props.name}</h1>;
}

function App() {
  return (
    <div>
      <Welcome name="Sara" />
      <Welcome name="Cahal" />
      <Welcome name="Edite" />
    </div>
  );
}

ReactDOM.render(
  <App />,
  document.getElementById('root')
);

In your component It's typo mistake.

Use props.onChange insted of props.handleChange

  • Related