Requirements:
Create two different components inside card. Component 1 is home component and component 2 is Name comp. Home comp having input text field with button name called Send. If user type in the text field and click on send button then in Name component same text field should appear.
Step1: Create Home component with following code.
import React, { Component } from 'react';
import Name from '../Name/Name.js';
import nameAction from '../../Actions/NameAction.js';
class Home extends Component {
constructor(props){
super();
this.state = {
name: ''
}
}
sendDataToAction=()=>{
nameAction(this.state.name);
}
render() {
return (
<div className='container mt-5'>
<div className='col'>
<div className='card'>
<div className='card-header'>
<input type="text" onChange= {(e)=>{
this.setState({
name:e.target.value
})
}}/>
<button className='btn btn-primary m-3' onClick={this.sendDataToAction}>Send</button>
</div>
<div className='card-body'>
<Name/>
</div>
</div>
</div>
</div>
)
}
}
export default Home
Step2: Create Name component with following code
import React, { Component } from 'react';
import {connect} from 'react-redux';
class Name extends Component {
render() {
return (
<div className='container mt-5'>
<div className='row'>
<div className='col'>
<p className='display-5'>{this.props.storeData}</p>
</div>
</div>
</div>
)
}
}
export default connect((storeData)=>{
return {
storeData: storeData.nameReducer.name,
};
},null)(Name)