kidkarolis / cherrytree-for-react Goto Github PK
View Code? Open in Web Editor NEWSeamlessly use cherrytree router with React
Seamlessly use cherrytree router with React
Right now a piece of middleware is installed that updates the Router component on transition start. This causes the component to be out of sync with the actual router. The initial app render can be used to demonstrate this:
Router
component is passed to ReactDOM.render
Router.componentWillMount
method installs middleware then starts the routerRouter.render
method returns nothing since router has not finished starting (no routes to render)Router
state, causes re-renderthis.context.router.state.routes
to get active routes but gets undefined
because router is in the middle of a transition.This is just one example of the inconsistencies; other issues occur if the transition is cancelled (the next state will be rendered upon transition start, but upon cancel won't get reverted to the previous state).
I think this could be solved by using transition.then
in the middleware, however we'd have to be careful since if the Router was unmounted mid-transition, we would end up calling setState
on an unmounted component.
Tried to install with react 0.14 today and had a peer dependency issue. Used npm 3 to get round it for now.
Right now if you want to provide additional props to a child route you need to clone it, leading to code like this:
class App extends Component {
render () {
return (
<div>
{React.cloneElement(this.props.children, { anotherProp: 'foo' })}
</div>
)
}
}
It would be much nicer IMO to have a <RouteHandler />
component like they do in react-router:
class App extends Component {
render () {
return (
<div>
<RouteHandler anotherProp='foo' />
</div>
)
}
}
This should be pretty easy to achieve. The RouteHandler component would look something like this:
class RouteHandler extends Component {
static childContextTypes = {
routes: PropTypes.array
}
static contextTypes = {
routes: PropTypes.array
}
getChildContext () {
return {
routes: routes.slice(1)
}
}
render () {
return this.context.routes[0]
}
}
Thoughts @KidkArolis ?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.