ReactLab
ReactLab
Batch – B Web-Technology
Output-
Q 2 Create three components in below mention hierarchy Problem Statement
In this case, if there is some Data only in component TextData but, component
Output Data also wants that data. We know Component cannot access the data
because a component can talk only to its parent or child (Not cousins). Solution
We can define that data in data class and pass then to child class as a props
Code-
import React, { Component } from 'react'
import TextData from './TextData'
import OutputData from './OutputData'
</div>
)
}
}
Q 3 Define MainHead component as ClassComponentclass Create defined a
state variable name inside constructor having initial value as “ ” In MainHead
Class component define a arrow function having one argument and function
name should be updateValue =(e) =>{ } that update the value of name variable
to the value written in text box by user . Hint updateValue=(newvalue)=> {
this.setState({name:newvalue}) } MainHead TextData OutputData
Code-
import React from 'react'
changeValue =(e)=>
{
this.props.update(e.target.value)
}
render() {
return (
<div>
<input type="text" onChange={this.changeValue}/>
{this.props.data}
</div>
)
}
}
Q 5 Create Another component OutputData as functional component that prints
name value passed by MainComponent as a props.
Output –