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

[Feature]: Undestructuring of props and automatic splitProps #5

Open
edemaine opened this issue Apr 4, 2022 · 2 comments
Open

[Feature]: Undestructuring of props and automatic splitProps #5

edemaine opened this issue Apr 4, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@edemaine
Copy link

edemaine commented Apr 4, 2022

Input code

import React from "react";

function Component1({name, count}) {
  return <div>Hello {name}! Count is {count}</div>;
}

function Component2({name, count, ...rest}) {
  return <div {...rest}>Hello {name}! Count is {count}</div>;
}

render(() => <Component />, document.getElementById("app"));

Expected Output

import { splitProps } from "solid-js";

function Component1(props) {
  return <div>Hello {props.name}! Count is {props.count}</div>;
}

function Component2(props) {
  const [local, rest] = splitProps(props, ["name", "count"]);
  return <div {...rest}>Hello {local.name}! Count is {local.count}</div>;
}

Additional context

Related work on the Babel front:

@edemaine edemaine added the enhancement New feature or request label Apr 4, 2022
@orenelbaum
Copy link

The problem here is that we need a way to know what is a component and what isn't.
Other than that we can just plug in one of those Babel plugins.

@edemaine
Copy link
Author

edemaine commented Apr 4, 2022

In my React code, every component is wrapped with React.memo, so that would help. Another common heuristic is "any function that has JSX in it"; eslint react rules tend to use that, though it's not always accurate.

I don't know how codemods are normally structured, but you could imagine it being interactive, asking some questions like "which of these functions are components?".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants