sei-ec-remote / team-project-issues

0 stars 0 forks source link

Error when trying to display subdocuments #136

Closed EricCSheppard closed 1 year ago

EricCSheppard commented 1 year ago

Describe the bug A clear and concise description of what the bug is.

Getting an error when trying to display the comments subdoc

What is the problem you are trying to solve?

trying to get our comments to display on our show page for an individual document

Expected behavior A clear and concise description of what you expected to happen.

Expecting to map over the array of comments on our document, and have them display below

What is the actual behavior? A clear and concise description of what actually happened.

An error is returned in the console.

Post any code you think might be relevant (one fenced block per file)

The comment map:

    let commentCards
    if (goal) {
        if (goal.comments.length > 0) {
            commentCards = goal.comments.map(comment => (

                <ShowComment
                    key={comment.id}
                    comments={comment}
                    user={user}
                    goal={goal}
                    msgAlert={msgAlert}
                    triggerRefresh={() => setUpdated(prev => !prev)}
                />

            ))
        }
    }

The ShowComment component:

import { Card, Button } from 'react-bootstrap'
import { useState } from 'react'

const ShowComment = (props) => {
    const { comment, user, goal, msgAlert, triggerRefresh } = props

    return (
        <>
            <Card>
                <Card.Header></Card.Header>
                <Card.Body>
                    {comment.note}
                </Card.Body>
                <Card.Footer>
                </Card.Footer>
            </Card>
        </>
    )
}

export default ShowComment

What is your best guess as to the source of the problem?

The error says there is something wrong with the casing of the react component

What things have you already tried to solve the problem?

I tried console logging the "commentCard" and this was returned:

Screen Shot 2023-02-15 at 12 00 19 PM

Additional context Add any other context about the problem here.

Error

Paste a link to your repository here

https://github.com/EricCSheppard/Project3-client/tree/eric

timmshinbone commented 1 year ago

The prop for comment on the ShowComment component is comments but you're referring to it inside the component as comment, change the prop name to the singular comment

EricCSheppard commented 1 year ago

Oops, that was a typo leftover from when I was changing things around, the error still exists when it's comment.

EricCSheppard commented 1 year ago

heading for lunch now so might be slow to reply if you get back.

timmshinbone commented 1 year ago

Weird, I'll take a look after lunch

EricCSheppard commented 1 year ago

Solved!

timmshinbone commented 1 year ago

Renamed component + Github weirdness was causing this issue. Making a new component with the same exact parts fixed the prob