(no title)
kfinley | 9 years ago
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.
hokkos|9 years ago
bostonvaulter2|9 years ago
kfinley|9 years ago
timdorr|9 years ago
It's basically idiomatic JS vs idiomatic React/JSX.
kfinley|9 years ago
Edit: To the idiomatic point. The first thing that struct me when using React, was that instead of having to use a custom Component for a for loop I could just use someArray.map(). I see this as a similar situation.
seangrogg|9 years ago
While React-Router had a lot of great convenience features I found that it was surprisingly easy to roll my own redux-compatible version that fit my personal needs with a few lines of code and no additional dependencies.
danabramov|9 years ago