roman01la / html-to-react-components

Converts HTML pages into React components
https://roman01la.github.io/html-to-react-components/
MIT License
2.13k stars 136 forks source link

add hooks to allow user to manipulate asts #12

Closed Chun-Yang closed 8 years ago

Chun-Yang commented 8 years ago

This is more of a suggestion instead of a PR.

@roman01la We want to extend the function of this component and do something like this:

<C1 data-props-users="users">
  <C2 data-props-user="users">
  <C2 data-props-user="users">
  <C2 data-props-user="users">
</C1>
// CONVERT TO
<C1>
  {
    this.props.users.map(
      function(user){ return <C2 user={user}> }
    )
  }
</C1>

Or something like this

<C1>
   user's name is <span data-value="user.name">John</span>,
   he has a car named <span data-value="car.name">Toyota</span>
</C1>
// CONVERT TO
<C1>
   user's name is <span>{this.props.user.name}</span>,
   he has a car named <span>{this.props.car.name}</span>
</C1>

There are several solutions for us:

  1. fork you repo and do PRs.
  2. extend your repo a little bit to allow users to hook into their own functionality into the conversion flow.

I am trying to do the second one. What do you think is the best?

BTW, thank you for your awesome package!

roman01la commented 8 years ago

Hello! I think this is a great idea. I do want to implement these kind of transformations, but it doesn't seem like a good idea to have them in the core library. So a simple plugins system would be very cool. Your contribution is very welcomed!