-
Notifications
You must be signed in to change notification settings - Fork 2
Open
Description
We could remove most of our dependencies by migrating to the latest version of React so we can get hooks and the context API.
The migration would include:
- Redux > the React Context API
- React Functional Lifecycle > React Hooks
- React Native / Native Components > We only have a handful of components, so it would be pretty simple to move them to abstractions for
Text,View, etc using html elements for web and native components for native. We could also improve the load by providing separate web and native build targets such as@aloompa/react-universal-router/domand@aloompa/react-universal-router/web. The animated components would be the most difficult to convert to DOM, but our animations are fairly simple and could be achieve with CSS - Recompose > React Hooks and functional composition
With all of those changes in place, implementing the entire router would be as simple as this:
import { useRouter, Router } from '@aloompa/react-universal-router/web';
const myRoutes = {
routes: {
Home: {
route: Home,
getTitle: () => 'Home'
},
AnotherRoute: {
route: AnotherComponent,
getTitle: () => 'Another Page'
},
}
};
const App = () => {
return (
<Router routes={myRoutes} />
);
}
const Home = () => {
const { setRoute } = useRouter();
return (
<button onClick={() => setRoute({ route: 'AnotherRoute' })}>Go to another page</button>
)
}
const AnotherComponent = () => {
const { setRoute } = useRouter();
return (
<button onClick={() => setRoute({ route: 'Home' })}>Go home</button>
)
}Metadata
Metadata
Assignees
Labels
No labels