Ok - this seems to work. Am I using this correctly?
import React from 'react';
import { observable } from 'mobx';
import { observer } from 'mobx-react';
import { CardTitle } from 'material-ui/Card';
import IconButton from 'material-ui/IconButton';
import ActionLockOpen from 'material-ui/svg-icons/action/lock-open';
import ActionLock from 'material-ui/svg-icons/action/lock';
@observer
export class Q6ATitle extends React.Component {
@observable canEditNew;
handleClick() {
this.canEditNew = !this.canEditNew;
this.props.output(!this.canEditNew);
}
renderTitle() {
if (this.props.lock) {
return (
<span>
{this.props.label}
<IconButton onClick={this.handleClick.bind(this)}>
{this.canEditNew ? <ActionLockOpen/> : <ActionLock/>}
</IconButton>
</span>
);
}
return this.props.label;
}
render() {
return (
<CardTitle title={this.renderTitle()}/>
);
}
}
Q6ATitle.propTypes = {
label: React.PropTypes.string.isRequired,
lock: React.PropTypes.bool.isRequired,
output: React.PropTypes.func,
};
It should be pointed out that i don’t really understand how to use stores. So in essence I am using Mobx to handle bits of UI state.
(1) I don’t have a constructor of any kind. How would i handle stuff that has to be instantiated on load without the component methods?
(2) Just pass in as props and change my class to a stateless component?
(3) Can someone explain how to use stores (like I’m 5 please)
(4) This seems like a dodgy implementation. It seems to me like i should pass in an observable prop (canEditNew above), and then the Q6ATitle component should just be a stateless component function. Thoughts?
Tat