I have finding difficault to pass the value form one component to another component in React Js. I have files like App.js and Home.JS
App.js have one input box and one h1 tag while typing on the input box the value will be displayed inside the h1 tag. I wants the same method whereas instead of displaying on the same page i want to display the same value in Home.js with React Router.
Appp.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class App extends Component {
constructor(){
super();
this.state = {
name : "sivaprakash",
age : 25
}
}
update(e){
this.setState({name: e.target.value})
}
render() {
return (
<div className="App">
<header className="App-header">
<img src={logo} width="50" height="50" className="App-logo" alt="logo" />
</header>
<section>
<h1>{this.state.name} - {this.state.age}</h1>
<form>
<input type="text" name="tx1" onChange={this.update.bind(this)} placeholder="Type Something..."/>
</form>
</section>
</div>
);
}
}
export default App;
Home.js
import React, { Component } from 'react';
import logo from './logo.svg';
import './App.css';
class Home extends Component {
constructor(){
super();
this.state = {
name : "",
}
}
render() {
return (
<div className="App">
<h1>{this.state.name} </h1>
</div>
);
}
}
export default Home;
Please let me know if my question seems confusing.