Skip to content

Remove depencies on Redux, React Functional Lifecycle, React Native Components and Recompose #26

@tysoncadenhead

Description

@tysoncadenhead

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/dom and @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

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions