Skip to content

Instantly share code, notes, and snippets.

@BrodaNoel
Created January 19, 2019 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save BrodaNoel/22be8c10f627422ec53d0f688adf7342 to your computer and use it in GitHub Desktop.
Save BrodaNoel/22be8c10f627422ec53d0f688adf7342 to your computer and use it in GitHub Desktop.
import React, { Component } from 'react';
import duix from 'duix';
// Pages
import Loading from './src/pages/Loading';
import Login from './src/pages/Login';
import Home from './src/pages/Home';
import Contact from './src/pages/Contact';
// ...more dependencies...
const DEFAULT_PAGE = 'Loading';
duix.set('currentPage', DEFAULT_PAGE);
class App extends Component {
state = {
currentPage: DEFAULT_PAGE
};
componentDidMount() {
duix.subscribe('currentPage', this.onCurrentPageChange);
}
onCurrentPageChange = (currentPage) => {
this.setState({ currentPage });
};
render() {
return (
<View style={[{ flex: 1 }]}>
{
{
Loading: <Loading />,
Login: <Login />,
Home: <Home />,
Contact: <Contact />
}[this.state.currentPage]
}
</View>
);
}
}
export default App;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment