cerebellum-react
lets you easily create isomorphic apps with Cerebellum & React.
This package contains a wrapper function that sets up everything for you, but you can also choose what helpers to include by requiring individual modules.
cerebellum-react wrapper will setup nested route mappings, route handler and renderer for you.
Use prependTitle
option to prepend a string to each component's static title.
With containerComponent
option you can create a layout component that can e.g. setup the context for all child components.
import React from 'react';
import ReactDOM from 'react-dom';
import Client from 'cerebellum/client';
import Cerebellum from 'cerebellum-react'
import options from './options';
options.prependTitle = "urls - ";
options.containerComponent = (store, component) => {
return Layout({
children: component,
store: store
});
};
Cerebellum(Client, React, ReactDOM, options);
When using route-handler
in conjunction with render
you get some really useful static methods for your route components.
route-handler
checks if your route returns a React component that defines title
and stores
properties and then returns it to be handled by render
.
With .title
You can provide title for your route component. Can be either function or static string.
With .stores
you can define what stores cerebellum will fetch when entering your route.
LinksIndex.stores = (request) => {
return {
"user": {},
"links": {page: request.params.page, sorting: request.query.sort}
};
}
With .preprocess
you can modify the props returned from stores before passing them as final props to the route component.
Tags.preprocess = (props, request) => {
if (request.params.id) {
props.selected = request.params.id;
props.tags = props.tags.filter(tag => tag.get("id") === request.params.id);
}
return props;
};
You should just use values from cerebellum's options.
You can pass containerComponent
function as option, the return value will be passed to React.render
.
Container components are useful if you need to set context for all child components.
With prependTitle you can prepend text to beginning of document's title. Rest of the title will be read from your route component's .title
.
If your app does not need immutable data structures, you can convert all props to plain JS objects with this option
import createRender from 'cerebellum-react/render'
options.render = createRender(React, ReactDOM, {
storeId: options.storeId,
appId: options.appId,
prependTitle: "My cool app - ",
containerComponent: (store, component) => {
return Layout({
children: component,
store: store
});
}
});
route-map
will generate nested route map of the components in your app.
options.routes = routeMap(routes);
You have to pass React as param because context gets always set as undefined
if different React instance renders the root component.
- Merge flat/nested renderers & route handlers
- Add tests for all modules
- Better documentation
- Create single wrapper for all modules so you don't have to require three different modules to get going