React
1
Вклад в тег
store.dispatch(someAction(data))
store.subscribe(() => {
console.log(...)
})
// 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>
}
}