Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

option to disable div wrapper (but keep all inside Component) #12

Closed
11111000000 opened this issue Nov 22, 2017 · 8 comments
Closed

option to disable div wrapper (but keep all inside Component) #12

11111000000 opened this issue Nov 22, 2017 · 8 comments

Comments

@11111000000
Copy link

import { Social } from 'modules/buttons'

<footer className="my-footer"></footer>

i.e. I want <footer></footer> , not <div><footer></footer></div>

@11111000000
Copy link
Author

11111000000 commented Nov 22, 2017

Or to add external wrapper only when top level inner divs more than one? (React restriction)

@11111000000 11111000000 changed the title option to disable div wrapper (but keep component wrapper) option to disable div wrapper (but keep all inside Component) Nov 22, 2017
@11111000000
Copy link
Author

any suggestions?

@jamesknelson
Copy link
Collaborator

You should be able to achieve this by setting the wrapper factory. For example, this will make the component render using an array wrapper instead of a div wrapper:

<MyMDXComponent factories={{
  wrapper: (props, ...children) => children
}} />

You can see how this works by looking at the generated JS:

import React, { createElement, createFactory } from 'react'

export default function({ factories={} }) {
  const {
    wrapper = createFactory('div'),
  } = factories

  return wrapper({},

createElement("footer", { className: "my-footer" })

  )
}

@11111000000
Copy link
Author

thanks! Want this example in documentation! And how to configure that as default behavior in webpack loader? (all our components have wrapper already)

@11111000000
Copy link
Author

And React 16 allow arrays returns...

@jamesknelson
Copy link
Collaborator

I don't think there is currently a way to configure default factories via the webpack loader (or at all, really).

This is something that has come up before. I'm going to re-open this one, but don't have time to work on it at the moment. If you have a good solution, I'd be happy to merge it.

@jamesknelson jamesknelson reopened this Nov 26, 2017
@simonlc
Copy link

simonlc commented Feb 18, 2018

I was getting an error about keys so I changed this:

<MyMDXComponent factories={{
  wrapper: (props, ...children) => children
}} />

To this:

<MyMDXComponent factories={{
  wrapper: (props, ...children) => React.Children.toArray(children),
}} />

@jamesknelson
Copy link
Collaborator

Closing this issue as I've deprecated mdxc in favor of https://github.com/mdx-js/mdx

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants