Use new lifecycle method to update component state.

- Use component state to handle rendering of Ansible Select dropdown based on the number of custom virtualenvs the API returns.
This commit is contained in:
kialam
2018-12-22 09:03:44 -05:00
parent e30b198418
commit 5fcdd16f54
2 changed files with 23 additions and 3 deletions

View File

@@ -76,6 +76,8 @@ class App extends React.Component {
const isNavOpen = typeof window !== 'undefined' && window.innerWidth >= parseInt(breakpointMd.value, 10);
this.state = {
isNavOpen,
config: {},
error: false,
};
}
@@ -94,9 +96,14 @@ class App extends React.Component {
async componentDidMount() {
// Grab our config data from the API and store in state
const { data } = await api.get(API_CONFIG);
this.setState({ config: data });
try {
const { data } = await api.get(API_CONFIG);
this.setState({ config: data });
} catch (error) {
this.setState({ error });
}
}
render() {
const { isNavOpen, config } = this.state;
const { logo, loginInfo, history } = this.props;