如何在React中向组件添加滚动条?

Kle*_*leo 2 css scrollbar reactjs

我在SPA中使用具有3列的网格系统。左右列表包含占据视口高度100的组件。中间一列包含一长串,并想向中间组件添加滚动条。我试图用几个不同的滚动条组件来填充中间组件,但是没有任何效果。我总是以主页滚动结尾,而当进一步向下滚动时,剩下的仅是列表组件,而左侧和右侧组件则保留在页面顶部。

ina*_*v17 8

尝试添加overflow-y: scroll;中间组件

const items = [...Array(100)].map((val, i) => `Item ${i}`);

const App = () => (
  <div className="container">
    <div className="left-col">
      Left col
    </div>
    
    <div className="center-col">
      <span>List</span>
      <ul>
        {items.map((item, i) => (<li key={`item_${i}`}>{ item }</li>))}
      </ul>
    </div>
    
    <div className="right-col">
      Right col
    </div>
  </div>
);

ReactDOM.render(<App />, document.getElementById('react'));
Run Code Online (Sandbox Code Playgroud)
.container {
  display: flex;
  flex-direction: row;
  height: 100vh;
}

.left-col {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #ddd;
}

.center-col {
  flex: 1;
  background: #aaa;
  overflow-y: scroll;
}

.right-col {
  flex: 1;
  display: flex;
  justify-content: center;
  align-items: center;
  background: #e7e7e7;
}
Run Code Online (Sandbox Code Playgroud)
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/15.1.0/react-dom.min.js"></script>

<div id="react"></div>
Run Code Online (Sandbox Code Playgroud)