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

new plugin: remove-side-effect #17

Open
wants to merge 9 commits into
base: main
Choose a base branch
from
Open

new plugin: remove-side-effect #17

wants to merge 9 commits into from

Conversation

XXXMrG
Copy link
Member

@XXXMrG XXXMrG commented Nov 18, 2024

Based on the discussion in issue #7007, I implemented a new SWC plugin: swc-plugin-remove-side-effect.

Its purpose is to remove side effect functions from React code, including:

  1. useEffect
  2. useLayoutEffect
  3. ...

根据 alibaba/ice#7007

实现了一个新的 swc plugin: swc-plugin-remove-side-effect
其作用是移除 react 代码中的副作用函数,包括:

  1. useEffect
  2. useLayoutEffect
  3. ...

@XXXMrG XXXMrG changed the title wip: new plugin: remove-side-effect new plugin: remove-side-effect Nov 18, 2024
@XXXMrG
Copy link
Member Author

XXXMrG commented Nov 18, 2024

@chenjun1011 @wssgcg1213 @ClarkXia Looking forward to your review!

@XXXMrG
Copy link
Member Author

XXXMrG commented Nov 18, 2024

Perhaps we can also consider handling useState, but that would be relatively more complex. I'll try to address it in a later commit.

Like this:

original:

function Component() {
  const [count, setCount] = useState(0);

  const handleClick = () => setCount(count + 1);

  return <div onClick={handleClick}>{count}</div>;
}

target:

function Component() {
  const [count] = useState(0);

  return <div>{count}</div>;
}

@XXXMrG
Copy link
Member Author

XXXMrG commented Nov 21, 2024

#16
DONE: upgrade swc_core

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

Successfully merging this pull request may close these issues.

1 participant