|
|
|
|
|
by kfinley
3567 days ago
|
|
Interesting change. If I understand correctly, basically you have a base component that updates fragments of the UI based on the route. const App = () => (
<BrowserRouter>
<h1>Hello World</h1>
<Match exactly pattern="/" component={Home} />
<Match pattern="/about" component={About} />
<Miss component={NoMatch}/>
</BrowserRouter>
)
Couldn't we take it one step farther and just use a switch statement? It seems like using pure JavaScript would be more idiomatic React. The URL pattern could be parsed in the data layer, and passed down as props. That way the components don't rely on global state, making them easier to test. const App = (screen, args) => {
let content;
switch (screen) {
case 'home':
content = <Home args={args} />
break;
case 'about':
content = <About args={args} />
break;
default:
content = <NoMatch args={args} />
break;
}
return (
<div>
<h1>Hello World</h1>
{content}
</div>
)
}
It's probably just a matter of preference. Recently I started using React-Storybook, so I've become addicted to "dumb" components. |
|