Giter Site home page Giter Site logo

rrx's Introduction

RRX

Minimal React router using higher order components

npm i -S rrx

Example Usage

// import React from 'react'
// import {
//   createRouter,
//   createView,
//   Link
// } from 'rrx'

const Home = createView((props) => (
  <div>
    <h1>Home</h1>
  </div>
))

const About = createView((props) => (
  <div>
    <h1>About</h1>
  </div>
))

const Post = createView(({
  params
}) => (
  <div>
    <h1>{params.title}</h1>
  </div>
))

class App extends React.Component {
  render () {
    return (
      <div>
        <nav>
          <ul>
            <li><Link href='/'>Home</Link></li>
            <li><Link href='/about'>About</Link></li>
            <li><Link href='/posts/hello'>Hello Post</Link></li>
          </ul>
        </nav>
        <Home pattern='/' />
        <About pattern='/about' />
        <Post
          pattern='/posts/:title'
          foo='bar'
        />
      </div>
    )
  }
}

const Router = createRouter(App)

const props = {
  options: {
    basename: '/rrx'
  }
}

render(<Router {...props} />)

API

createRouter

Higher order component to create a wrapper Router component. This component creates a history object and provides context for both history and location.

Router components provide these objects through context:

  • history - the history object from history
  • location - the location object from history
const App = () => (
  <div>
    <h1>Hello</h1>
  </div>
)

export default createRouter(App)

createView

Creates a view component that accepts a pattern prop for route matching. If the location matches the pattern, the component will render with params and search props. If it does not match, it will not render.

View component props:

Props provided by the HOC:

  • params - object of URL parameters from the given pattern.
  • search - the location.search string
const About = () => (
  <h1>About</h1>
)

export default createView(About)
import About from './About'

const App = () => (
  <div>
    <About pattern='/about' />
  </div>
)

export default createRouter(App)

<Link />

A Link component that uses the history context to transition between routes using the browser History API.

<Link href='/about'>
  About
</Link>

GitHub Made by Jxnblk

MIT License

rrx's People

Contributors

jxnblk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

Forkers

rayyee

rrx's Issues

Bump version for PropTypes

When you removed the deprecated API PropTypes a version bump would be helpful. Had to do

yarn remove rrx
yarn add rrx

go get latest changes.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.