I'm just starting with React and it seems just beautifull to create user interfaces, however, I do have problem with communication between components.
I do have a very simple react component, representing a button:
import React from 'react';
export default class OfficeUIButton extends React.Component {
constructor(props) {
super(props);
this.state = {
active: false,
};
// Bind the event handlers.
this.onMouseDownEventHandler = this.onMouseDownEventHandler.bind(this);
this.onMouseUpEventHandler = this.onMouseUpEventHandler.bind(this);
}
onMouseDownEventHandler() {
this.setState({
active: true
});
}
onMouseUpEventHandler() {
this.setState({
active: false
});
}
render() {
return <div className={"officeui-button" + (this.state.active ? ' active': '')} onMouseDown={this.onMouseDownEventHandler}
onMouseUp={this.onMouseUpEventHandler}>
<span className="officeui-button-label">{this.props.text}</span>
</div>
}
}
This component has a state property named active
. Based on the state, an additional class is added to the button.
Let's assume that I have 2 of these OfficeUIButton
components on my page, how can I, by clicking the first button, make the second button active?
This is just a dummy example, but I need this for example for a modal popup, or for disabling buttons based on a certain action.
Thanks for the help.