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

Refactoring #11

Open
pjchender opened this issue Sep 29, 2020 · 1 comment
Open

Refactoring #11

pjchender opened this issue Sep 29, 2020 · 1 comment

Comments

@pjchender
Copy link

pjchender commented Sep 29, 2020

const handleUserDelete = (e, email) => {

可以試試看這種寫法:

// 原本
  const handleUserDelete = (e, email) => {
    e.stopPropagation();
    e.preventDefault();
    dispatch({
      type: "REMOVE_COLLABORATOR_REQUEST",
      payload: {
        email,
        postId: roomId ? roomId : null,
      },
    });
  };

// 後來
const handleUserDelete = email => e  => {
    e.stopPropagation();
    e.preventDefault();
    dispatch({
      type: "REMOVE_COLLABORATOR_REQUEST",
      payload: {
        email,
        postId: roomId ? roomId : null,
      },
    });
}

使用的時候會變這樣:

// 原本
<i
  className="far fa-trash-alt deleteIcon"
  onClick={(e) => {
    handleUserDelete(e, i.userEmail);
  }}
/>

// 後來
<i
  className="far fa-trash-alt deleteIcon"
  onClick={handleUserDelete(i.userEmail)}
/>

同時附上 commits 中的 comments

@pjchender
Copy link
Author

Auto check this commits(3654437cfa6)

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

No branches or pull requests

1 participant