1

I cant display array object in map function. Could someone please tell me why ? When Im trying to display this object in the console I see it correctly.

class ProductsGrid extends React.Component {
constructor(props) {
    super(props);
}
render() {
    return (<Table striped bordered condensed hover>
        <thead>
            <tr>
                <th>Id</th>
                <th>Name</th>
                <th>Description</th>
                <th>Url</th>
            </tr>
        </thead>
        <tbody>
            {this.props.products !== null ?
                JSON.parse(this.props.products).map((product, index) => {
                    <tr>
                        {console.log(product.IdProduct)}
                        <td>{product.IdProduct}</td>
                        <td>{product.Name}</td>
                        <td>{product.Description}</td>
                        <td>{product.UrlFriendlyName}</td>
                    </tr>
                }) : <tr><td></td><td></td><td></td><td></td></tr>}
        </tbody>
    </Table>);
}}
3
  • 7
    Does your map function need a return? Commented Apr 8, 2017 at 10:54
  • Ofcourse.. What a stupid mistake, sorry..I've spend on this like one hour. Commented Apr 8, 2017 at 10:55
  • I've made many of those mistakes in my decades of programming :-) I hope my answer helps the next person who does this. Commented Apr 8, 2017 at 11:00

1 Answer 1

3

Your map function needs a return statement.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.