navyblueyes
navyblueyes

Reputation: 47

Object Passed to Component Becomes Empty

I am making a simple Quiz app using React Hooks.

I pass a question object into a ResultModel component.

Passing the question object into the ResultModel Here I console.log the question object before passing it into the ResultModel component.

Console.logging question Here I console.log the question object inside of ResultModel component.

Console shows that question loses its properties Here is the result... I get an empty question object.

Upvotes: 1

Views: 651

Answers (1)

Nicholas Tower
Nicholas Tower

Reputation: 85022

You're missing the curly brackets for destructuring the props. The variable you've called question is actually the context object.

The fix is to do this:

export default function ResultModal({ isCorrect, question, getQuestion}) {

Or if you prefer, don't destructure in the argument list:

export default function ResultModal(props) {
  const { isCorrect, question, getQuestion } = props;

Upvotes: 4

Related Questions