Replies: 2 comments
-
I am facing the same issue. Tightly coupling a |
Beta Was this translation helpful? Give feedback.
0 replies
-
And what is your async function deleteUser(_url, { arg }) {
await fetch(`/users/${arg}`, {
method: 'DELETE',
})
// probably some headers goes here
}
const { trigger } = useSWRMutation('thisIsKeyNotNecessarilyUrl', deleteUser);
const handleUserRemove = (id) => {
trigger(id);
} |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
👋🏻 Hey there,
I'm new to
SWR
and I'm trying to adoptuseSWRMutation
in my project and I've stumbled upon an issue I'm not sure how to solve with this hook.I've an API endpoint to remove a user based on their
id
:Then, I have a component that renders all users and this component is responsible to handle all the logic & actions (eg. removing users):
handleUserRemove
gets user id as and argument:And this is where I have the problem:
One of the solutions could be moving the "remove" responsibility down to
Users
component, like this:But it doesn't follow the pattern I use across the whole application - in my case
User
component is "dumb", it should be generic and without any business logic. Of course I could create a wrapper only to handle the remove action:but I would like to avoid such wrappers.
Any ideas are appreciated 🙏🏻
Beta Was this translation helpful? Give feedback.
All reactions