Przeglądaj źródła

should not setState before mount

afc163 7 lat temu
rodzic
commit
c93b0169a5
1 zmienionych plików z 18 dodań i 21 usunięć
  1. 18 21
      src/pages/Account/Settings/Info.js

+ 18 - 21
src/pages/Account/Settings/Info.js

@@ -15,30 +15,27 @@ export default class Info extends Component {
   constructor(props) {
     super(props);
     const { match, location } = props;
+    const menuMap = {
+      base: <FormattedMessage id="app.settings.menuMap.basic" defaultMessage="Basic Settings" />,
+      security: (
+        <FormattedMessage id="app.settings.menuMap.security" defaultMessage="Security Settings" />
+      ),
+      binding: (
+        <FormattedMessage id="app.settings.menuMap.binding" defaultMessage="Account Binding" />
+      ),
+      notification: (
+        <FormattedMessage
+          id="app.settings.menuMap.notification"
+          defaultMessage="New Message Notification"
+        />
+      ),
+    };
+    const key = location.pathname.replace(`${match.path}/`, '');
     this.state = {
       mode: 'inline',
-      menuMap: {
-        base: <FormattedMessage id="app.settings.menuMap.basic" defaultMessage="Basic Settings" />,
-        security: (
-          <FormattedMessage id="app.settings.menuMap.security" defaultMessage="Security Settings" />
-        ),
-        binding: (
-          <FormattedMessage id="app.settings.menuMap.binding" defaultMessage="Account Binding" />
-        ),
-        notification: (
-          <FormattedMessage
-            id="app.settings.menuMap.notification"
-            defaultMessage="New Message Notification"
-          />
-        ),
-      },
+      menuMap,
+      selectKey: menuMap[key] ? key : 'base',
     };
-    let key = location.pathname.replace(`${match.path}/`, '');
-    const { menuMap } = this.state;
-    key = menuMap[key] ? key : 'base';
-    this.setState({
-      selectKey: key,
-    });
   }
 
   static getDerivedStateFromProps(props, state) {