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]: Transform ReactJS useRef into simple let #3

Open
edemaine opened this issue Apr 4, 2022 · 1 comment
Open

[Feature]: Transform ReactJS useRef into simple let #3

edemaine opened this issue Apr 4, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@edemaine
Copy link

edemaine commented Apr 4, 2022

Input code

import React, { useRef } from "react";
import { render } from "react-dom";

const Component = () => {
  const ref = useRef();
  useEffect(() => {
    ref.current.style.color = "purple";
  }, []);
  return <div ref={ref}>Hello!</div>;
};

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

Expected Output

import { render } from "solid-js/web";

const Component = () => {
  let ref;
  useEffect(() => {
    ref.style.color = "purple";
  }, []);
  return <div ref={ref}>Hello!</div>;
};

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

Additional context

In addition to removing useRef and replacing const with let, ideally we could remove the .current suffix after every ref.

A challenge is that refs shouldn't be passed into functions though; you'd need to wrap them in functions.

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

milahu commented Nov 1, 2022

done in react-use-ref-to-solid-let

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