Answer the question
In order to leave comments, you need to log in
How to get props from another class component?
Good afternoon
There is a code
Component 1
import React from 'react';
class Block1 extends React.Component {
constructor(props: any){
super(props);
}
render() {
return (
<div className="block">
<h2 className="block__title">{this.props.title}</h2>
<span className="block__value">{this.props.value}</span>
</div>
)
}
}
export default Block1;
import React from 'react';
import data from './data' // json file
class Block2 extends React.Component {
this.state = {
data: data,
showModal: false
};
openModal = () => {
this.setState({ showModal: true })
}
closeModal = () => {
this.setState({ showModal: false })
}
render() {
return (
{this.state.data.map((data: any, index: any) => {
<a href="#" onClick={this.openModal}>
<span>Link {data.title}</span><span>{data.value}</span>
</a>
})}
<div className="modal" show={this.state.showModal} handleClose={this.closeModal}>
<Block1 title={this.data.title} value={this.data.value} />
</div>
)
}
}
export default Block2;
Компонет Block2
displays a list of blocks from json file
, in turn, this block is a link, when clicked, I try to get data in a pop-up window. Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question