I want to fire an onClick function when I click on any of my children "postItem" components. With what I have now, the clicked components won't do anything, unless the onClick function is outside the map function (such as in a new separate component)
import React, { Component } from "react"; import axios from "axios"; import PostItem from "./postItem"; import "../styles/socialFeed.css"; class SocialFeed extends Component { constructor(props) { super(props); this.state = { posts: [] }; this.showBox = this.showBox.bind(this); } showBox(postItem) { console.log(this); } componentDidMount() { this.Posts(); } Posts() { axios .get( "randomapi" ) .then(res => { const posts = res.data.data; this.setState({ posts }); }); } render() { let { posts } = this.state; let allPosts = posts.map(post => ( <PostItem key={post.id} {...post} onClick={this.showBox} /> )); return <div className="social-feed">{allPosts}</div>; } } export default SocialFeed; is it incorrect to pass a function through a map?
PostItemcode.PostItem.