如何在 reactjs 中列出来自状态的数组?

How to list array from state in reactjs?

我刚开始研究 reactjs 并尝试显示来自状态的项目列表,这是我的主要组件的片段:

const render = () => ReactDOM.render(
  <div>
    <AddButton

      addToList={() => store.dispatch(
        {
          type: 'ADDTEXT',
          payload: {
            text: 'this is a text'
          }
        }
      )}
    />

    <List items="store.getState()"></List>
  </div>

  ,
  rootEl
)

我希望将状态注入到数组列表中。 列表如下所示:

import React, { PropTypes } from 'react'
import Item from './Item'

const List = ({ items }) => (
  <ul>
    {items.map(item =>
      <Item
        key={item.id}
        {...item}

      />
    )}
  </ul>
)
//


export default List

但是我收到这个错误:

Uncaught TypeError: items.map is not a function

完整代码位于:https://github.com/dimitri-a/counter_react/examples/counter

您不应将 items 作为字符串 store.getState() 传递。试试这个:

<List items={store.getState()}></List>