Skip to main content

mutate

Method meant to modify the store's data, when the method is called the reducer will perform the corresponding mutation base on the type and all the store's subscribers will be notified, let's explore this by following the demo: file explorer

Parameter

keyvaluerequireddescription
typestringtrueEvent type
targetsstring[] or number[]falseList of subscribers to be notified on states mutations
payloadobjecttrueMutation payload
warning

Important: If the targets parameter is not passed then all the store's subscribers will be notified on states mutations otherwise only the subscribers in the list will be notified.

Example

const { mutate } = useStore({
/* ... */
});

const handleClick = () => {
mutate({
type: CONSTANTS.SET_FILE_STATE,
targets: [
/*...*/
],
payload: { value: "" },
});
};
tip

Pro tip: After the useStore is initialized the mutate method can be accessed through the store

import explorer from "@/store/explorer";
explorer.mutate(/*...*/);