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

Add passNode option to pass props.node #22

Merged
merged 5 commits into from
Jul 24, 2020

Conversation

Rokt33r
Copy link
Contributor

@Rokt33r Rokt33r commented Jul 22, 2020

Fixes #19

And I added a type alias, ComponentProps because I found that type inference for component's props argument doesn't work. So adopters who want to access props, they have to set ComponentProps manually.

unified().use(rehypeToReact, {
  createElement: React.createElement,
  passNode: true,
  components: {
    a: (props) => <a>{props.node}</a> // This will throws an error because `props` is considered as `any` implicitly.
  }
})

So I need to fix like

unified().use(rehypeToReact, {
  createElement: React.createElement,
  passNode: true,
  components: {
    a: (props: { node? unist.Node}) => <a>{props.node}</a>
    // Or like this with `ComponentProps`
    // a: (props: rehypeToReact.ComponentProps) => <a>{props.node}</a>
  }
})

@codecov-commenter

This comment has been minimized.

@ChristianMurphy ChristianMurphy requested a review from a team July 22, 2020 15:06
@ChristianMurphy ChristianMurphy added ☂️ area/types This affects typings 🗄 area/interface This affects the public interface 🦋 type/enhancement This is great to have 🧒 semver/minor This is backwards-compatible change labels Jul 22, 2020
Copy link
Member

@wooorm wooorm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks fine to me!

@ChristianMurphy Can you confirm on the types?

readme.md Outdated Show resolved Hide resolved
@wooorm wooorm changed the title Introduce pass node Add passNode option to pass props.node Jul 24, 2020
@wooorm wooorm merged commit 985b705 into rehypejs:main Jul 24, 2020
@wooorm
Copy link
Member

wooorm commented Jul 24, 2020

Thanks @Rokt33r, released in 6.1.0!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🗄 area/interface This affects the public interface ☂️ area/types This affects typings 💪 phase/solved Post is done 🧒 semver/minor This is backwards-compatible change 🦋 type/enhancement This is great to have
Development

Successfully merging this pull request may close these issues.

Expose HAST nodes to components
4 participants