Guest User

Untitled

a guest
Jan 16th, 2019
79
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.65 KB | None | 0 0
  1. class MyComponent extends Component {
  2.  
  3. constructor() {
  4. this.prop1 = this.props.prop1;
  5. this.prop2 = this.props.prop2;
  6. }
  7.  
  8. render() {
  9. //....
  10. }
  11.  
  12. onEvent(e) {
  13. this.setState({
  14. prop1: getProp1(),
  15. prop2: this.prop2()
  16. });
  17. }
  18. }
  19.  
  20. class MyState {
  21.  
  22. update(params) {
  23. this.prop1 = getProp1();
  24. }
  25.  
  26. }
  27.  
  28.  
  29. class MyComponent extends Component {
  30.  
  31. constructor() {
  32. this.state.obj = this.props.obj; // this has type MyState
  33. }
  34.  
  35. render() {
  36. //....
  37. }
  38.  
  39. onEvent(e) {
  40. this.obj.update(e.something);
  41. this.setState(this.obj);
  42. }
  43. }
Add Comment
Please, Sign In to add comment