Skip to content

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