bier hier bier hier - 1 month ago 5
React JSX Question

How to list array from state in reactjs?

I just started looking at reactjs and trying to display a list of items from state, this is a fragment of my main component:

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

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

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

,
rootEl
)


I was hoping to inject the state into the list which is an array.
List looks like this:

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


However I am getting this error:

Uncaught TypeError: items.map is not a function


The complete code sits in:https://github.com/dimitri-a/counter_react/examples/counter

Answer

you shouldn't pass items as a string store.getState(). Try this :

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