Bug: working with render props
See original GitHub issueIsn’t possible to reproduce render props component like that:
import { Foo } from './Foo'
# Hello Foo
<Foo>
{() => {
const bar = 'bar'
return (
<Bar bar={bar} />
)
}}
</Foo>
I noticed that in the MDAST => MDXAST
process you just turn HTML
into JSX
nodes, but in this case the line breaks between const
and return
is a trade off, because the parse is a Paragraph
instead of the same scope of HTML
.
So, I was trying to figure out how fix this and I think that what can be a possible solution is create something like a merge between nodes when the HTML
node that has the opening tag is invalid (without enclosing tag). I don’t know if this can generate some trade offs or is a solution that fit in all cases. So, I didn’t think yet how this can affect performance, but was the only thing that came in mind in that case 😞
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:18 (8 by maintainers)
Top Results From Across the Web
this.props is duplicating to the next component sometimes bug ...
The error seems to be when I call super(props) as it uses the props from the previous component. When I render it, it's...
Read more >A Story of a React Re-Rendering Bug - Engineering Blog
We know, by default, one React component will only be re-rendered if its state gets changed, either caused by props change, or triggered...
Read more >React's Render Props in Practice - Medium
If you are a front-end developer using ReactJS, you've probably caught a lot of buzz about render props and how they are supposed...
Read more >React re-renders guide: everything, all at once - Developer way
Comprehensive guide on React re-renders. The guide explains what are re-renders, what is necessary and unnecessary re-render, ...
Read more >How React Uses Closures to Avoid Bugs
props (you shouldn't do that). I'm talking about when the parent component re-renders and passes new props, this.props suddenly points to completely new...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Just to give some context to @erquhart’s comment/question:
For the initial MDX implementation I kept in mind a very strict superset of Javascript (or not even JS, as JSX is not JS), the only thing MDX parses are
import
export
andjsx
jsx is handled by unified, we convert thehtml
nodes tojsx
nodes for consistency. import/export are parsed in the simplest way possible, if the ast node starts withimport
/export
it’s an import/export, if not it’s normal text.I’ve always thought that writing render props / other JS in MDX documents doesn’t make sense as it introduces unnecessary complexity and there are other ways to handle it, for example as you can use JSX you could move that code into a component and make that component render everything you need.
It’s also a good idea to keep in mind that soon render props will in most cases be replaced by Hooks.
The only case that is interesting to explore deeper is the possibility to write JSX inside of markdown syntax like
**<Something />**
which is currently not possible. I know @johno has been playing around with this idea for a while though.So the only reason Pedro’s example doesn’t work is the empty line break between const and return, remark Will parse that as 2 paragraph nodes