Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

179
Views
passing props from parent to child (while the child is the parent himself) react js

there is a Chat component (parent), it passes the value of props, which stores the data id, img Id, chatName in Conversation (child), in which they are rendered. the Conversation component has a ConversationItem component, that is, Conversation is the parent of the ConversationItem. The ImgId must be passed from the Conversation component to the ConversationItem. to draw it there.

Here is an example of my code

Chat

const Chat = () => {
return (
    <div className='app1'>
        <ConversationList/>
        {
            user.map(conversation =>

                <Conversation
                    key={conversation.id}
                    data={conversation}
                />
            )
        }

    </div>
);
}
export default Chat;

Conversation

export default function Conversation(props) {
        const {id, imgId, chatName} = props.data;
        const messages = JsonData;
        return (
    
            <div>
                <div >
                    <img src={imgId} />
                </div>
                <div >
                    {messages.map((message) => {
                            return (
                                <ConversationItem message={message} imgId={imgId} key={message.mes_id}/>)
                        }
                    )}
                </div>
            </div>
        );
    }

ConversationItem

const ConversationItem = ({message}, imgId) => {
    return (
        <div>
                    <div className="img_cont_msg">
                        <img src={imgId.data}/>
                    </div>
                    <div classname = "msg-text">
                        
                            {message.text_msg}
                    </div>
            
        </div>
    );
};

export default ConversationItem;

at the moment, the code transmits something and outputs not a placeholder, but a void. if I do

<img src={imgId.data}/>

to

<img src={imgId}/>

the placeholder image not found will be displayed. how to implement it correctly?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

You are not correctly destructuring the props in the ConversationItem component. Instead do this:

const ConversationItem = ({ message, imgId }) => {
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!