JavaScript for WordPress Forums Gutenberg Development Confused by Spread operator

Viewing 1 post (of 1 total)
  • Author
    Posts
  • #46007
    R B ATTENBOROUGH
    Participant

    This line in example 7 index.js confuses me:

    isSelected && <Inspector { ...{ setAttributes, ...props} } />,

    As I understand it the ... spreads out all the elements inside an array or object so [1, 2, 3] would return 1, 2 and 3.

    But to then to create a object literal with a spread array inside it and then to spread the object itself, yeah, that confuses me.

    This has all come about because I actually want to pass another argument to the Inspector, but can’t figure out how.
    I’ve tried:

    isSelected && <Inspector { ...{setAttributes, ...props, { editor: this.editorInstance } } } />,

    and

    isSelected && <Inspector { ...{setAttributes, ...props }, { editor: this.editorInstance } } />,

    but neither seems to work…(!)

    Thanks.

Viewing 1 post (of 1 total)
  • You must be logged in to reply to this topic.