Skip to content


Folders and files

Last commit message
Last commit date

Latest commit



30 Commits

Repository files navigation

React Layout

Dynamic subview layout for React

Define layout of nested views with fixed and flexible dimensions in a declarative manner.

Why? If you still have to support IE9 and below, flexbox is off the table. However, flexibly sized elements are necessary for many complex layouts.


var React = require('react')
var Layout = require('react-layout')
var AppViews = require('./app-views')

var AppLayout = React.createClass({
  getInitialState: function() {
    // a resizable sidebar could be implemented by updating this value
    return {sidebarWidth: 330}
  render: function() {
    var scrollable = {
      'overflow-y': 'scroll',
      'overflow-x': 'hidden',

    return (
      <Layout layoutWidth={this.props.width} layoutHeight={this.props.height}>
        <Layout className="sidebar" layoutWidth={this.state.sidebarWidth}>
          <AppViews.Sidebar />
        <Layout className="main" layoutWidth="flex" style={scrollable}>
          <AppViews.Main />

function render() {
  var appView = (
  React.render(appView, document.body)

window.addEventListener('resize', render)


This example implements a two-panel app layout with a sidebar and main viewport. The sidebar gets its width from a state value and the main view fills the remaining width.

When the window is resized, the app is rerendered and the new window dimensions flow down the layout hierarchy.


The Layout component provided by this module can be parametised with the props layoutWidth and layoutHeight, both which take a layoutDef value, which can be any of the following:

  • numeric pixel value eg. layoutHeight={100}: will apply a fixed size in pixels for that dimension
  • "flex": will fill the remaining space left by fixed size sibling Layout elements components taking part in layout for that dimension. If there are multiple 'flex' components, they will share the available space evenly.
  • "omit": the element will not be given any size value for this dimension

If no layoutDef value is provided for a particular dimension, the Layout component will inherit the size for that dimension from the parent component (or the closest parent Layout component) as a fixed size.

Other props:

  • component: a React component class to use for the layout element (defaults to div)