Constructor
constructor(props){
super(props);
this.state = {
itemData: []
};
}
savePost = (item, index) => {
fetch( API , {
method: 'POST',
headers: {
'Accept': 'application/json',
'Content-Type': 'application/json',
},
}).then(data=> {
const items = Object.assign([], this.state.itemData);
item[index].save_post_status=true;
this.setState(this.state, {itemData:items });
})
}
inside render
{ this.state.itemData.map((item,index) => {
<li>
<Link to="#!" className="trans" title="Save" value={item.id} data-id={item.id} onClick={()=> savePost(item, index)}>
<img className="svg" src={ siteurl + "/src/assets/images/save.svg"} alt="Save" />
{ item.save_post_status === false ? "Save" : "Post Saved" }
</Link>
</li>
}})
Try above code, may be it will help you!!