Skip to content

Instantly share code, notes, and snippets.

@jh3y
Created November 5, 2020 12:58
Show Gist options
  • Select an option

  • Save jh3y/55fb48f4dba81bc3c5e9097f3c3d0531 to your computer and use it in GitHub Desktop.

Select an option

Save jh3y/55fb48f4dba81bc3c5e9097f3c3d0531 to your computer and use it in GitHub Desktop.

Revisions

  1. jh3y created this gist Nov 5, 2020.
    17 changes: 17 additions & 0 deletions optional-props.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    const myObject = {
    a: 1,
    b: 2,
    ...(false && { c: 3 }),
    }
    // myObject: { a: 1, b: 2 }

    const myObject = {
    a: 1,
    b: 2,
    ...(true && { c: 3, d: 4 }),
    }
    // myObject: { a: 1, b: 2, c: 3, d: 4 }

    const MyComponent = () => {
    return <SomeOtherComponent {...(passOptionalProps && { cool: true, message: '👋' })} />
    }