-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feature request: Add "props" property on jsx node types #419
Comments
Interesting 🤔. Would you then expect the JSX output to be?: <MyComponent foo={{ bar: 'baz' }} /> Also, could you elaborate on your use case a bit? |
Yeah exactly! I guess the use case would be whenever you need to pass a prop that is an object. In my specific use case I'm trying to emulate gatsby-remark-images but with a custom React component instead of a regular There might be a better solution to my problem that I'm unaware of 😄 |
Just noticed that children of the component aren't presented as children in the AST. This makes it a bit difficult to work with imo. So <Column width="50%">

</Column> is parsed as { type: 'jsx',
value: '<Column width="50%">',
position: [Position] },
{ type: 'text', value: '\n' },
{ type: 'element',
tagName: 'img',
properties: [Object],
children: [],
position: [Object] },
{ type: 'text', value: '\n' },
{ type: 'jsx', value: '</Column>', position: [Position] }, I might be unaware of any underlying issues but I think it would be a lot easier if it instead parsed to { type: 'jsx',
value: 'Column',
props: {width: '50%' },
position: [Position],
children: [
{ type: 'text', value: '\n' },
{ type: 'element',
tagName: 'img',
properties: [Object],
children: [],
position: [Object] },
{ type: 'text', value: '\n' },
]
}, |
Based on this comment this is something we can address in #241 for 1.1.0. |
Subject of the issue
AFAIK there is no way to pass props to the component from a plugin without inlining it in the value e.g.
<Image foo="bar" />
. What I'd like to see is the ability to add props with anode.props
field as well. That would be helpful if you need to pass props that are an object for example.Plugins would then be able to do this:
The text was updated successfully, but these errors were encountered: