0

I have tried to assign multiple this.props properties at once in the Child Component:

const {readings, wantRead, read} = this.props;

When I tried to use readings as the props in the next child component, it seems just undefined and error out.

But here the weirdest stuff is if I first assign the this.props properties one by one like:

const readings = this.props.currentlyReading;

Then used the readings inside the next child component, it just works fine.

Not really sure what happened at first????

keikai
  • 11,706
  • 7
  • 39
  • 59
qmkiwi
  • 105
  • 5

1 Answers1

1

when you use Destructuring assignment (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment) like you did:

const {readings, wantRead, read} = this.props;

What you need to put in between brackets ({}) is the name of the variable present in this.props, that you want to access.

So you need to use currentlyReading instead of reading:

const {currentlyReading, wantRead, read} = this.props;

source + explication : https://stackoverflow.com/a/52286807/6809926

Zenocode
  • 566
  • 4
  • 18