WDI-SEA / project-4-issues

Open an issue to receive help on project 4 issues
0 stars 0 forks source link

Understanding the code, comment not posting inside user array #34

Closed DagemBefikadu closed 2 years ago

DagemBefikadu commented 2 years ago

What stack are you using?

(ex: MERN(mongoose + react), DR(django + react), PEN, etc.)

What's the problem you're trying to solve?

I can successfully post a comment but i cant see it in the campaign array

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


export default function NewComment(props) {
    const [addComment, setAddComment] = useState([])

    let newParam = useParams()  

    const createdComment = (e) => {
        e.preventDefault()
        console.log("this is params:", props.user._id)
    axios({
        url: apiUrl + `/campaigns/${newParam}/comments`,
        method: "POST",
        headers: {
            Authorization: `Token token=${props.user.token}`,
        }, 
        data: {
            comment: {
                commented: e.target.newComment.value,
                campaignId: newParam.id,
                owner: props.user._id
            }
        }   
    })
    .then((res) => console.log("server response:", res))
    .catch((err) => console.log(err));
}

If you see an error message, post it here. If you don't, what unexpected behavior are you seeing?

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

I feel like i need another then statment

What things have you already tried to solve the problem?

timmshinbone commented 2 years ago

Show me the model for comment and the route used to add them

TaylorDarneille commented 2 years ago

What's the update on this?

DagemBefikadu commented 2 years ago

Solved!