Update singletype Strapi V4 record

How can I update a single type record on strapi?
3 Replies
kapa.ai
kapa.ai2mo ago
Hi @LoadedDie. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave: ---------------------- To update a single type record in Strapi V4, you can use the useUpdate hook provided by Refine. However, there was a bug reported on Github where the useUpdate hook was working without error but changes were not reflecting on Strapi. The issue was with the data provider where the data was being passed at the start of the payload. The solution was to pass only the variables for Strapi V4 as it doesn't require you to pass data at the start of your payload. Here is the code snippet from the Github issue:
// Original code
const { mutate } = useUpdate<DataType>({
resource: "resourceName",
variables: { id: record.id, data: { ...record, fieldToUpdate: newValue } },
});

// Updated code
const { mutate } = useUpdate<DataType>({
resource: "resourceName",
variables: { id: record.id, fieldToUpdate: newValue },
});
// Original code
const { mutate } = useUpdate<DataType>({
resource: "resourceName",
variables: { id: record.id, data: { ...record, fieldToUpdate: newValue } },
});

// Updated code
const { mutate } = useUpdate<DataType>({
resource: "resourceName",
variables: { id: record.id, fieldToUpdate: newValue },
});
Please note that this is a general example and you might need to adjust it according to your specific use case. For more details, you can refer to the Github issue (https://github.com/refinedev/refine/issues/1482). ---------------------- Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: ----------------------
kapa.ai
kapa.ai2mo ago
<@403364125578625024> kapa.ai is still learning and improving, please let us know how it did by reacting below
foreign-sapphire
foreign-sapphire2mo ago
However single-types dont have an ID on strapi