I have done an array.map() that loop through json file (goods.json). Then I want to make some manipulations with it (want to delete item from this array in removeCard(obj) method for example). Render is ok but the problem is that I don't understand why I can't see shoppingCardsJSX array in removeCard(obj) method, always get underfined. I have read answers in How to delete a ToDo Item onClick in React? and Remove item from array in React but unfortunately I didn't understand how it works. Can you please help me find out what I'm doing wrong ? Hope this part of code can illustrate my problem,
import { sample } from 'rxjs/internal/operators';
import React from 'react';
import ShoppingCard from './ShoppingCard';
import goods from './goods.json';
export default class ShoppingCards extends React.Component {
constructor (props){
super(props);
}
removeCard(obj){
console.log("fireeeee");
console.log(obj);
console.log(this.shoppingCardsJSX);
}
render() {
console.log("render");
let shoppingCardsJSX = goods.map((good) => {
return (
<ShoppingCard
key = {good.id }
goodId = {good.id}
src = {good.src}
price = {good.price}
onRemoveCard={this.removeCard}
/>
);
});
console.log(shoppingCardsJSX);
return shoppingCardsJSX;
}
}
<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>