I use lightweight ORM to connect my application to an external service ... This package returns the objects of your model and allows you to perform operations directly against them. Although it’s really amazing, I’m struggling to figure out how I can turn these objects state
on and still follow “never modify the state directly” to react to it.
If I had a component that updated the account name, would it be acceptable to do something like this?
interface IAppState {
account: Account
}
class App extends React.Component<{}, IAppState> {
constructor(props) {
super(props);
this.state = {
account: new Account()
}
}
public updateAccount = (newName: string)=>{
account.name = newName;
acc.update().then(()=>{
this.setState({ account: this.state.account })
})
}
public componentDidMount() {
const qParams = queryString.parse(window.location.search);
Account.get(qParams.externalId).then((acc)=>{
this.setState({account: acc})
})
}
render() {
return <NameEditor handleClick={this.updateAccount} account={a} />
}
}
, , ORM, , , . , ORM ORM-, .
, "" " "???
Update
- , , , , react/addons
... , , ORM ? , insert
.