Skip to content

investigate the macro-component syntaxΒ #17

@mathieudutour

Description

@mathieudutour

there is a new lib (https://github.com/jxnblk/macro-components) that does pretty much what we are doing it but that have a lot more constraints and is more fragile (jxnblk/macro-components#3).

But the API is pretty neat, looks better than seapig. We could do something similar really easily tho:

instead of

import seapig, { OPTIONAL, REQUIRED } from 'seapig'

const Main = props => {
  const {
    sidebarChildren, // array of children with the `sidebar` prop
    contentChildren  // array of children with the `content` prop
  } = seapig(props.children, { // schema object
    sidebar: OPTIONAL, // sidebar is optional
    content: REQUIRED  // content is required
  })

  // rendering order is always the same
  return (
    <div>
      {sidebarChildren.length && <aside>{sidebarChildren}</aside>}
      <section>{content}</section>
    </div>
  )
}

we could have

import seapig from 'seapig'

const Main = seapig(({
    sidebar,
    content
  }) => {
  return (
    <div>
      {sidebar.length && <aside>{sidebar}</aside>}
      <section>{content}</section>
    </div>
  )
})

we lose the schema but maybe it can be an optional second argument to the seapig function

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions