-
-
Notifications
You must be signed in to change notification settings - Fork 27
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
Expose HAST nodes to components #19
Comments
What would this look like? Do you get the whole subtree of the node that is to be compiled? Can you access The simplest solution I can think of to begin solving it is: // Ensure no React warnings are triggered for void elements having children
// passed in.
result =
- elements.length === 0 ? h(name, attributes) : h(name, attributes, elements)
+ elements.length === 0 ? h.call(node, name, attributes) : h.call(node, name, attributes, elements)
// Restore parent schema.
ctx.schema = parentSchema ...as passing it in props will probably cause things to fail because some tools would serialize ...then we have access to it here: Lines 39 to 43 in 761597e
...and can choose to put it in a prop for components? |
For now, I just need to access the node being compiled. But I guess some users might want to access whole subtree too.
The solution looks good to me. Is there any way to modify the |
The first example shows how We could then change function h(name, props, children) {
var component = name
if (has.call(components, name)) {
component = components[name]
props.node = this
}
return createElement(component, props, children)
} |
LGTM. And I think we should make it optional too for users who are using prop-types package. So I guess I should submit a pr to hast-to-hyperscript first? |
PR to h2h is a good first step, I don’t see a harm in changing that. I do feel like an option to pass |
How is it weird? |
I mean, a single option |
I think this sounds enough in my opinion.
I think this can be done while transforming. So I don't think we need it. |
Alright, sounds like we have a plan! Are you interested / able to work on it? |
Yeah, I'll do it tonight or tomorrow! |
Closes GH-23. Related to rehypejs/rehype-react#19. Reviewed-by: Titus Wormer <[email protected]>
So this is 50% there. Last part is to update here, right? |
@Rokt33r No rush at all, but a friendly ping! |
Ah sorry. I'll do it now..! I was too busy... |
Related to: syntax-tree/hast-to-hyperscript#23. Closes GH-19. Closes GH-22. Reviewed-by: Christian Murphy <[email protected]> Reviewed-by: Titus Wormer <[email protected]>
Released in 6.1.0! |
Subject of the feature
I want to access HAST nodes from React components to use position or custom attributes of nodes when rendering.
Problem
For now, there is no way to access because rehype-react is tightly bound to hast-to-hyperscript, which consumes Node.
Expected behavior
A React component should be able to access its Node info somehow.
Alternatives
Passing a node instance via
node
prop.The text was updated successfully, but these errors were encountered: