jsxtreme-markdown icon indicating copy to clipboard operation
jsxtreme-markdown copied to clipboard

option for react-16 JSX array (no wrapping div)

Open graingert opened this issue 8 years ago • 6 comments

in:

Foo

bar

out:

[
  <p key="1">Foo</p>
  <p key="2">bar</p>
]

graingert avatar Oct 12 '17 14:10 graingert

Ah, interesting ... I guess this would be an option for toJsx, which would then make it available to all the higher-level functions.

The way things currently work, I'm afraid this might end up being more trouble than it's worth, because we'd need to parse the string output of htmltojsx to add a key attribute to every top-level element, right?

I've occasionally tinkered with the possibility of switching from htmltojsx to https://github.com/algolia/react-element-to-jsx-string, and with that package's latest release it may have fixed the last blocking bug I know of. I wonder if that would enable the feature you're looking for, @graingert.

davidtheclark avatar Oct 12 '17 14:10 davidtheclark

I simply use React.Fragment as a wrapper to avoid polluting the DOM. Not sure if that's what @graingert is asking for.

MathiasSM avatar May 10 '18 21:05 MathiasSM

A fragment would do too, it's just that the array form was supported earlier

graingert avatar May 10 '18 21:05 graingert

Oh, sorry (I didn't know).

MathiasSM avatar May 10 '18 21:05 MathiasSM

Maybe I'm missing something, but is the Wrapper supposed to wrap around a <div />, that ultimately wraps around the entire content? The structure I'm seeing is

<Wrapper>
	<div>
		<p>...</p>
		<p>...</p>
		<p>...</p>
	</div>
</Wrapper>

I thought the wrapper was supposed to replace the <div /> (hence, my above comments). Again, I may be missing something. If the div is always there, would you mind let us know? A custom template would then remove it at will (in a really ugly but "It works" way, of course).

MathiasSM avatar May 10 '18 21:05 MathiasSM

@MathiasSM it's because returning more than one JSX element was impossible before react 16

graingert avatar May 10 '18 21:05 graingert