New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cherrytree-for-react

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cherrytree-for-react

An adapter for cherrytree router for using it with React

  • 0.0.4
  • npm
  • Socket score

Version published
Weekly downloads
2
decreased by-75%
Maintainers
1
Weekly downloads
 
Created
Source

cherrytree-for-react

Use the cherrytree router in your React applications. This project provides a React component that you should put at the root of your render tree. The component handles hot reloading.

Usage

$ npm install --save cherrytree cherrytree-for-react
import React from 'react'

import createCherrytree from 'cherrytree'
import { Router } from 'cherrytree-for-react'
import * as components from './components'

import { Provider } from 'redux/react'
import { createDispatcher, createRedux, composeStores } from 'redux'
import * as stores from './stores'

const {
  Application,
  About,
  GithubStargazers,
  GithubRepo,
  GithubUser
} = components

const redux = createRedux(createDispatcher(composeStores(stores)))

const cherrytree = createCherrytree()
  .map(routes)
  .use(function redirect (transition) {
    transition.routes.map(route => {
      if (route.options.redirect)
        cherrytree.replaceWith.apply(cherrytree, route.options.redirect)
    })
  })
  .use(function error (transition) {
    transition.catch(err => console.error(err.stack))
  })

export default class App extends React.Component {
  render () {
    return (
      <Provider redux={redux}>
        {() => <Router router={cherrytree} />}
      </Provider>
    )
  }
}

function routes (route) {
  route('app', { path: '/', component: Application }, () => {
    route('about', { path: 'about', component: About })
    route('stargazers', { path: 'stargazers', component: GithubStargazers }, () => {
      route('repo', { path: ':username/:repo', component: GithubRepo })
      route('user', { path: ':username', component: GithubUser })
    })
    route('index', { path: '', redirect: [ 'user', { username: 'KidkArolis' }] })
  })
}

Note: this example demonstrates how you'd use cherrytree-for-react with redux. If you don't use redux, simply use Router component at the top level, instead of the Provider.

The router will be injected into the context of the render tree. You can use it to generate links or initiate transitions, e.g.

let transition = this.context.router.transitionTo('repo', {username: 'facebook', repo: 'react'})
let url = this.context.router.generate('repo', {username: 'facebook', repo: 'react'})

Browse cherrytree repo for more docs and examples.

Server Side Usage

This component can also be used in the server side, in that case, an already started cherrytree instance needs to be passed in, e.g.

// start listening
cherrytree.listen(new cherrytree.MemoryLocation('/foo/bar')).then(function () {
  React.renderToString(<Router router={cherrytree} />)
})

In this case, the <Router> component will detect that the router has already been started and will not call the asynchronous listen function.

For a full, working server side example, see the cherrytree/examples/server-side-example.

WIP

This repo was just created and is a work in progress. The code is in es6 atm and so you'll need to have a compilation pipeline if you want to use this lib. I just haven't spent the time of setting up the prenpm compilation for this one. Do you have a good boilerplate?

A full working redux + react + cherrytree + hot reloading example is also coming soon.

FAQs

Package last updated on 09 Aug 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc