0

I'm trying to render card from data and also binding this to the constructor but still, I'm getting this error on all the line where this is used.

class SamplePage2 extends Component {

constructor() {
    super()
    this.state = { accordionKey: 0, data: [] }
}

render() {

    const { accordionKey } = this.state;

    return (
        <Aux>
            <Row>         
                <div className="card-height">
                    {this.state.data.map(function (item, key) {
                        return (
                            <Card className='Recent-Users' key={key}>
                                <Card.Body className='px-0 py-2'>
                                    <Table responsive hover>
                                        <tbody>
                                            <tr className="unread" onClick={() => this.setState({ accordionKey: (accordionKey !== { key } + 1) ? { key } + 1 : 0 })} aria-controls="accordion1" aria-expanded={accordionKey === { key } + 1}>
                                                <td>
                                                    <h6 className="mb-1">{item.appName}</h6>
                                                </td>
                                                <td>
                                                    <h6 className="mb-1">{item.appState}</h6>
                                                </td>
                                            </tr>
                                        </tbody>
                                    </Table>
                                    <Collapse in={this.state.accordionKey === { key } + 1}>
                                        <div id="accordion1">
                                            <Card.Body>
                                                <Card.Text>
                                                    Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon official.
                                                    </Card.Text>
                                            </Card.Body>
                                        </div>
                                    </Collapse>
                                </Card.Body>
                            </Card>
                        )
                    })}
                </div>            
            </Row>
        </Aux>
    );
}

}

export default SamplePage2;

Sam
  • 471
  • 7
  • 24
  • 2
    Your `map` callback is a traditional function and you haven't supplied `map`'s optional `thisArg`, so `this` within that callback will be the default, which in strict mode (the default for modules) is `undefined`. Just make it an arrow function instead. – T.J. Crowder Aug 29 '19 at 14:56
  • Sure Thanx @T.J.Crowder – Sam Aug 29 '19 at 14:59

0 Answers0