Skip to content

Commit

Permalink
prefer mutate over mutateAsync
Browse files Browse the repository at this point in the history
  • Loading branch information
alan2207 committed May 10, 2024
1 parent b52d0c7 commit 0b98df5
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 17 deletions.
4 changes: 2 additions & 2 deletions src/components/layouts/dashboard-layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ type SideNavigationItem = {
};

export function DashboardLayout({ children }: { children: React.ReactNode }) {
const { mutate: logout } = useLogout();
const logout = useLogout();
const { checkAccess } = useAuthorization();
const navigate = useNavigate();
const navigation = [
Expand Down Expand Up @@ -143,7 +143,7 @@ export function DashboardLayout({ children }: { children: React.ReactNode }) {
<DropdownMenuSeparator />
<DropdownMenuItem
className={cn('block px-4 py-2 text-sm text-gray-700 w-full')}
onClick={() => logout({})}
onClick={() => logout.mutate({})}
>
Sign Out
</DropdownMenuItem>
Expand Down
4 changes: 2 additions & 2 deletions src/features/comments/components/create-comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ export const CreateComment = ({ discussionId }: CreateCommentProps) => {
>
<Form
id="create-comment"
onSubmit={async (values) => {
await createCommentMutation.mutateAsync({
onSubmit={(values) => {
createCommentMutation.mutate({
data: values,
});
}}
Expand Down
4 changes: 1 addition & 3 deletions src/features/comments/components/delete-comment.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export const DeleteComment = ({ id, discussionId }: DeleteCommentProps) => {
isLoading={deleteCommentMutation.isPending}
type="button"
variant="destructive"
onClick={async () =>
await deleteCommentMutation.mutateAsync({ commentId: id })
}
onClick={() => deleteCommentMutation.mutate({ commentId: id })}
>
Delete Comment
</Button>
Expand Down
4 changes: 2 additions & 2 deletions src/features/discussions/components/create-discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const CreateDiscussion = () => {
>
<Form
id="create-discussion"
onSubmit={async (values) => {
await createDiscussionMutation.mutateAsync({ data: values });
onSubmit={(values) => {
createDiscussionMutation.mutate({ data: values });
}}
schema={createDiscussionInputSchema}
>
Expand Down
4 changes: 2 additions & 2 deletions src/features/discussions/components/delete-discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ export const DeleteDiscussion = ({ id }: DeleteDiscussionProps) => {
isLoading={deleteDiscussionMutation.isPending}
type="button"
variant="destructive"
onClick={async () =>
await deleteDiscussionMutation.mutateAsync({ discussionId: id })
onClick={() =>
deleteDiscussionMutation.mutate({ discussionId: id })
}
>
Delete Discussion
Expand Down
4 changes: 2 additions & 2 deletions src/features/discussions/components/update-discussion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ export const UpdateDiscussion = ({ discussionId }: UpdateDiscussionProps) => {
>
<Form
id="update-discussion"
onSubmit={async (values) => {
await updateDiscussionMutation.mutateAsync({
onSubmit={(values) => {
updateDiscussionMutation.mutate({
data: values,
discussionId,
});
Expand Down
2 changes: 0 additions & 2 deletions src/features/discussions/routes/__tests__/discussion.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ test('should update discussion', async () => {
const titleUpdate = '-Updated';
const bodyUpdate = '-Updated';

console.log('fakeDiscussion', fakeDiscussion.title);

await userEvent.click(
screen.getByRole('button', { name: /update discussion/i }),
);
Expand Down
4 changes: 2 additions & 2 deletions src/features/users/components/update-profile.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ export const UpdateProfile = () => {
>
<Form
id="update-profile"
onSubmit={async (values) => {
await updateProfileMutation.mutateAsync({ data: values });
onSubmit={(values) => {
updateProfileMutation.mutate({ data: values });
}}
options={{
defaultValues: {
Expand Down

0 comments on commit 0b98df5

Please sign in to comment.