Browse Source

ref(js): Convert AppRoot to a functional component (#28925)

Evan Purkhiser 3 years ago
parent
commit
0b8ba03184
1 changed files with 12 additions and 13 deletions
  1. 12 13
      static/app/views/app/root.tsx

+ 12 - 13
static/app/views/app/root.tsx

@@ -1,4 +1,4 @@
-import {Component} from 'react';
+import {useEffect} from 'react';
 import {browserHistory, RouteComponentProps} from 'react-router';
 
 import {DEFAULT_APP_ROUTE} from 'app/constants';
@@ -21,20 +21,19 @@ type Props = {
  * TODO: There might be an edge case where user does not have `lastOrganization` set,
  * in which case we should load their list of organizations and make a decision
  */
-class AppRoot extends Component<Props> {
-  componentDidMount() {
-    const {config} = this.props;
-
-    if (config.lastOrganization) {
-      browserHistory.replace(
-        replaceRouterParams(DEFAULT_APP_ROUTE, {orgSlug: config.lastOrganization})
-      );
+function AppRoot({config}: Props) {
+  useEffect(() => {
+    if (!config.lastOrganization) {
+      return;
     }
-  }
 
-  render() {
-    return null;
-  }
+    const orgSlug = config.lastOrganization;
+    const url = replaceRouterParams(DEFAULT_APP_ROUTE, {orgSlug});
+
+    browserHistory.replace(url);
+  }, []);
+
+  return null;
 }
 
 export default withConfig(AppRoot);