// componentA.jsx
class ComponentA extends React.PureComponent {
state = {
mounted: false
}
removeB = () => {
this.setState({ mounted: !this.state.mounted })
}
render() {
let { mounted } = this.state
return <div>
{
(mounted) ? <ComponentB /> : <ComponentC onClick={this.removeB} />
}
</div>
}
}
// componentB.jsx
class ComponentB extends React.PureComponent {
render() {
return <div>ComponentB</div>
}
}
// componentC.jsx
class ComponentC extends React.PureComponent {
render() {
return <button onClick={this.props.onClick}>ComponentC click me</button>
}
}
var self = this
componentDidMount() {
const myHeaders = new Headers({
"Content-Type": "application/json",
Accept: "application/json"
})
var self = this
fetch("https://jsonplaceholder.typicode.com/todos/1", { // ваш URL
headers: myHeaders,
}).then(response => {
return response.json();
}).then(data => {
self.setState({ data });
})
}
store.dispatch(someAction(data))
store.subscribe(() => {
console.log(...)
})