const baseURL = "http://localhost:4000/test";
import React from 'react';
import axios from 'axios';
import ImageComponent from "./imageComponent";
class ButtonComponent extends React.Component {
constructor(props){
super(props);
this.state = {
lalka: '',
isLoading: false,
};
this.click = this.click.bind(this);
}
onTrigger = (data) => {
this.props.parentCallback(data);
}
click() {
this.setState({ isLoading: true });
axios.get(baseURL, )
.then((response) => {
this.onTrigger(response.data)
})
.catch((err) => {
console.log(err);
});
}
render() {
return (
<div>
<button onClick={this.click} > click me </button>
</div>
);
}
}
export default ButtonComponent;
import React, { Component } from 'react';
import ButtonComponent from "./customBtn";
class ImageComponent extends Component {
constructor(props){
super(props);
}
state = {
name: "",
}
handleCallback = (childData) =>{
this.setState({name: childData})
}
render() {
const {name} = this.state;
return(
<div>
<ButtonComponent parentCallback = {this.handleCallback} />
{name}
</div>
)
}
}
export default ImageComponent;