Skip to content

Commit

Permalink
feat(project): add root component
Browse files Browse the repository at this point in the history
  • Loading branch information
RCVZ committed Apr 28, 2021
1 parent 12d1797 commit 577b963
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 9 deletions.
32 changes: 23 additions & 9 deletions src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,29 @@
import React from 'react';

import Slider from './containers/Slider'
import React, { Component } from 'react';
import { BrowserRouter as Router } from 'react-router-dom';

import Root from './components/Root/Root';
import './styles/main.scss';

function App () {
return (
<div className="App">
<Slider />
</div>
);
interface State {
error: Error | null;
}

class App extends Component<State> {
public state: State = {
error: null,
};

componentDidCatch(error: Error) {
this.setState({ error });
}

render() {
return (
<Router>
<Root error={this.state.error} />
</Router>
);
}
}

export default App;
31 changes: 31 additions & 0 deletions src/components/Root/Root.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import React, { FC } from 'react';
import { Route, Switch } from 'react-router-dom';

// import styles from './Root.module.scss';

const Home = () => {
return <span>Home</span>;
};

const PlaylistScreen = () => {
return <span>PlaylistScreen</span>;
};

interface RootProps {
error: Error | null;
}

const Root: FC<RootProps> = ({ error }: RootProps) => {
if (error) {
return <span>{error}</span>;
}

return (
<Switch>
<Route path="/" component={Home} exact />
<Route path="/p/:id" component={PlaylistScreen} exact />
</Switch>
);
};

export default Root;

0 comments on commit 577b963

Please sign in to comment.