Add getInitialState method to Entity component
authorFrank Bessou <frank.bessou@logilab.fr>
Tue, 02 May 2017 10:31:59 +0200
changeset 149 ac11d4378e29
parent 148 8c0ca4705fab
child 150 85fec823255c
Add getInitialState method to Entity component It will be used when props are updated to reinitialize the component.
src/components/Entity.js
--- a/src/components/Entity.js	Tue May 02 10:22:17 2017 +0200
+++ b/src/components/Entity.js	Tue May 02 10:31:59 2017 +0200
@@ -162,7 +162,7 @@
 
     constructor(props) {
         super(props);
-        this.state = {entity: null};
+        this.state = this.getInitialState(props);
         this.getEditionSchema = this.getEditionSchema.bind(this);
         this.updateEntity = this.updateEntity.bind(this);
         this.deleteEntity = this.deleteEntity.bind(this);
@@ -170,6 +170,10 @@
         this.navigateToSelf = this.navigateToSelf.bind(this);
     }
 
+    getInitialState() {
+        return {entity: null};
+    }
+
     getEType() {
         return this.props.match.params.etype;
     }