これらのライブラリは、React アプリケーションのユーザーインターフェース構築における異なるアプローチを代表しています。react-bootstrap と rebass は事前構築されたコンポーネントを提供し、react-flexbox-grid、react-grid-system、react-grid-layout はレイアウト構造に特化しています。一方、styled-components はスタイリングそのものを解決するエンジンです。これらを比較することで、プロジェクトの規模や要件に合わせた適切なアーキテクチャ選定が可能になります。
React エコシステムには、UI 構築のための多くのライブラリが存在しますが、それぞれが解決する課題は異なります。今回は、コンポーネントキット、グリッドシステム、スタイリングエンジンという 3 つのカテゴリに分類される 6 つのパッケージを比較します。これらは単に「見た目」を作るだけでなく、プロジェクトの保守性や拡張性に直接影響を与えます。
レイアウトをどう組むかは、プロジェクトの根幹に関わります。各パッケージがどのようにグリッドやコンテナを定義するかを見てみましょう。
react-bootstrap は、Bootstrap 5 のグリッドシステムを React コンポーネントとしてラップしています。
Container、Row、Col コンポーネントで構成されます。// react-bootstrap
import { Container, Row, Col } from 'react-bootstrap';
function Layout() {
return (
<Container>
<Row>
<Col xs={12} md={6}>Left</Col>
<Col xs={12} md={6}>Right</Col>
</Row>
</Container>
);
}
react-flexbox-grid は、flexboxgrid.css 仕様に基づいたグリッドを提供します。
Grid、Row、Col を使用します。// react-flexbox-grid
import { Grid, Row, Col } from 'react-flexbox-grid';
function Layout() {
return (
<Grid>
<Row>
<Col xs={12} md={6}>Left</Col>
<Col xs={12} md={6}>Right</Col>
</Row>
</Grid>
);
}
react-grid-system は、Bootstrap に似た構文を持ちつつ、特定の CSS フレームワークに依存しないグリッドです。
Container、Row、Col で構成されますが、実装は独自です。// react-grid-system
import { Container, Row, Col } from 'react-grid-system';
function Layout() {
return (
<Container>
<Row>
<Col xs={12} md={6}>Left</Col>
<Col xs={12} md={6}>Right</Col>
</Row>
</Container>
);
}
react-grid-layout は、静的なグリッドではなく、インタラクティブなレイアウト用です。
layout プロパスで座標を定義します。// react-grid-layout
import ResponsiveGridLayout from 'react-grid-layout';
function Dashboard() {
const layout = [{ i: 'a', x: 0, y: 0, w: 6, h: 2 }];
return (
<ResponsiveGridLayout className="layout" layout={layout}>
<div key="a">Widget A</div>
</ResponsiveGridLayout>
);
}
rebass は、グリッドというよりプリミティブなコンポーネント集ですが、レイアウトに使われました。
Box や Flex コンポーネントで構成します。// rebass (Deprecated)
import { Box, Flex } from 'rebass';
function Layout() {
return (
<Box>
<Flex>
<Box width={1 / 2}>Left</Box>
<Box width={1 / 2}>Right</Box>
</Flex>
</Box>
);
}
styled-components はグリッドシステムではありませんが、CSS Grid や Flexbox を使って自作できます。
// styled-components
import styled from 'styled-components';
const Grid = styled.div`
display: grid;
grid-template-columns: 1fr 1fr;
`;
function Layout() {
return (
<Grid>
<div>Left</div>
<div>Right</div>
</Grid>
);
}
スタイルをどのように管理するかは、開発体験に大きな影響を与えます。
react-bootstrap は、Bootstrap のクラス名を内部で使用します。
// react-bootstrap
// 内部で .btn .btn-primary などのクラスが適用される
<Button variant="primary">Click</Button>
react-flexbox-grid も同様に、定義済みの CSS クラスに依存します。
flexboxgrid.css の読み込みが必須です。// react-flexbox-grid
// 内部で .row .col-xs-12 などのクラスが適用される
<Row>
<Col xs={12}>Content</Col>
</Row>
react-grid-system も CSS クラスベースのアプローチです。
// react-grid-system
// 内部でグリッド用のクラスが適用される
<Row>
<Col sm={6}>Content</Col>
</Row>
react-grid-layout は、スタイルより動作に焦点を当てています。
// react-grid-layout
// style={{ position: 'absolute', ... }} のようなインラインスタイルが使われる
<ResponsiveGridLayout>
<div>Item</div>
</ResponsiveGridLayout>
rebass は、Style System に基づいていました。
// rebass
// props で色や余白を指定する
<Box color="tomato" p={3}>Content</Box>
styled-components は、コンポーネント内にスタイルを定義します。
// styled-components
const Button = styled.button`
background: tomato;
padding: 10px;
color: white;
`;
// 使用
<Button>Click</Button>
ライブラリを選ぶ際、それが将来も使い続けられるかは重要です。
react-bootstrap: 活発にメンテナンスされており、Bootstrap 5 への対応も完了しています。長期的な利用に安心感があります。react-grid-layout: ダッシュボード用途では事実上の標準であり、継続的に更新されています。styled-components: CSS-in-JS の代表的なライブラリとして、大きなコミュニティに支えられています。react-flexbox-grid: 更新が停滞しており、現代の CSS Grid 機能で代用可能なケースが多いです。react-grid-system: 維持されていますが、ネイティブの CSS 機能の進化により必要性は低下しています。rebass: 公式にメンテナンスが終了しています。 新規プロジェクトで使用すべきではありません。後継の Theme UI への移行が推奨されています。| 特徴 | react-bootstrap | react-flexbox-grid | react-grid-layout | react-grid-system | rebass | styled-components |
|---|---|---|---|---|---|---|
| 主な用途 | UI コンポーネント | 静的グリッド | 動的グリッド | 静的グリッド | UI プリミティブ | スタイリング |
| スタイル方式 | CSS クラス | CSS クラス | インライン/状態 | CSS クラス | Props/CSS | CSS-in-JS |
| 保守状況 | ✅ 活発 | ⚠️ 停滞 | ✅ 活発 | ✅ 維持 | ❌ 終了 | ✅ 活発 |
| 学習コスト | 低 | 低 | 中 | 低 | 低 | 中 |
| カスタマイズ | 中 | 低 | 高 | 中 | 高 | 最高 |
これら 6 つのパッケージは、同じ「UI 構築」という文脈にありながら、役割が明確に分かれています。
react-bootstrap は、スピードと標準性が求められる業務システムやプロトタイプに最適です。デザインの一貫性を保ちながら、素早く画面を作れます。
react-grid-layout は、ユーザーが配置をカスタマイズできるような特殊なダッシュボードを作る場合の唯一の選択肢と言えます。他のグリッドシステムでは実現できない機能です。
styled-components は、デザインシステムを自作したいチームや、コンポーネントとスタイルを密接に結びつけたい場合に適しています。自由度が高い分、設計の責任も開発者にあります。
react-flexbox-grid、react-grid-system、rebass については、新規プロジェクトでの採用は慎重になるべきです。特に rebass は使用を避け、react-flexbox-grid と react-grid-system については、ネイティブの CSS Grid や Flexbox、あるいは Tailwind CSS などのユーティリティファーストなアプローチで代用できないか検討してください。
最終的には、チームのスキルセットとプロジェクトの寿命を考慮して、最も保守しやすい構成を選ぶことが重要です。
既存の Bootstrap デザインシステムを採用したい場合や、企業向けダッシュボードなど標準的な UI コンポーネントを素早く必要とする場合に選択します。Bootstrap 5 に対応しており、jQuery 不要でモダンな React 環境で動作します。
CSS Grid が普及する前に作成されたレガシープロジェクトの維持や、特定の flexboxgrid.css 仕様に基づいたレイアウトが必要な場合にのみ検討します。新規プロジェクトではよりモダンな代替案を推奨します。
ユーザーがウィジェットをドラッグ&ドロップしたりサイズ変更したりできるダッシュボードを構築する場合に最適です。他のグリッドシステムとは異なり、インタラクティブなレイアウト変更に特化しています。
Bootstrap のグリッド構造に似ているが、特定の UI キットに依存しない軽量なグリッドシステムが必要な場合に適しています。ただし、ネイティブの CSS Grid や Flexbox で代用可能なケースが増えています。
このパッケージは公式にメンテナンスが終了しており、新規プロジェクトでの使用は推奨されません。代わりに後継である Theme UI や、他のコンポーネントライブラリの採用を検討すべきです。
CSS を JavaScript 内に閉じ込め、コンポーネント単位でスタイルを管理したい場合に選択します。テーマ機能や動的スタイリングが必要で、チームが CSS-in-JS パターンに慣れている場合に適しています。
Bootstrap 5 components built with React.
React-Bootstrap is compatible with various versions of Bootstrap. As such, you need to ensure you are using the correct combination of versions.
See the below table on which version of React-Bootstrap you should be using in your project.
| Bootstrap Version | React-Bootstrap Version | Documentation |
|---|---|---|
| v5.x | 2.x | Link |
| v4.x | 1.x (not maintained) | Link |
| v3.x | 0.33.x (not maintained) | Link |
If you would like to update React-Bootstrap within an existing project to use Bootstrap 5, please read our docs for migrating to React-Bootstrap V2.
If you would like to update React-Bootstrap within an existing project to use Bootstrap 4, please read our docs for migrating to React-Bootstrap V1.
Yarn is our package manager of choice here. Check out setup
instructions here if you don't have it installed already.
After that you can run yarn run bootstrap to install all the needed dependencies.
From there you can:
yarn test (Or run them in watch mode with yarn run tdd).yarn startyarn run buildClick here to explore some React-Bootstrap CodeSandbox examples.
Click here to automatically open CodeSandbox with the React-Bootstrap CodeSandbox Examples GitHub Repository as a workspace.
Yes please! See the contributing guidelines for details.