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

[FEAT]: useCreateMany() should accept MutateFunction params #6114

Closed
alicanerdurmaz opened this issue Jul 9, 2024 · 0 comments · Fixed by #6116
Closed

[FEAT]: useCreateMany() should accept MutateFunction params #6114

alicanerdurmaz opened this issue Jul 9, 2024 · 0 comments · Fixed by #6116
Assignees
Labels
enhancement New feature or request

Comments

@alicanerdurmaz
Copy link
Member

alicanerdurmaz commented Jul 9, 2024

Is your feature request related to a problem? Please describe.

Here is the usage of the useCreateMany hook:

import { useCreateMany } from "@refinedev/core";

const { mutate } = useCreateMany();

mutate(
  {
    resource: "products",
    mutationMode: "optimistic",
    successNotification: false,
    values: [
      {
        name: "Product 1",
        material: "Wood",
      },
      {
        name: "Product 2",
        material: "Metal",
      },
    ],
  },
  {
    onSuccess: () => {
      /* do something after mutation success */
    },
  },
);

In this use case, all parameters except the values are static. However, when I want to use the mutate function in different places, I have to rewrite these values, which can cause code duplication.

Describe the thing to improve

To improve developer experience, the useCreateMany() hook can directly pass all required values to the mutate function. This will reduce code duplication and improve readability.

New API:

import { useCreateMany } from "@refinedev/core";

const Demo = () => {
  const { mutate } = useCreateMany({
    resource: "products",
    mutationMode: "optimistic",
    successNotification: false,
    values: [
      {
        name: "Product 1",
        material: "Wood",
      },
      {
        name: "Product 2",
        material: "Metal",
      },
    ],
    mutationOptions: {
      onSuccess: () => {
        /* do something after mutation success */
      },
    },
  });

  const handleUpdate = (values) => {
    mutate(;
  };

  return /* Your JSX code here */;
};
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

Successfully merging a pull request may close this issue.

3 participants