-
QuestionHow can I use a dynamic amount of mutations with Use caseI have a plugin table and need to synchronize state between two buttons: Single plugin installation button: const PluginInstallationButton = (props: PluginInstallationButtonProps) => {
const { pluginType, pluginName, pluginVersion, pluginId } = props;
const [installPlugin, installationResult] = useInstallPluginMutation({
fixedCacheKey: pluginId
});
const onInstallClick = (
pluginName: string,
pluginType: string,
pluginVersion: string
) => {
installPlugin({
pluginVersion: pluginVersion,
pluginName: pluginName,
pluginType: pluginType
});
};
return (<Button loading={installationResult.isLoading} />)
}; Install all plugins button: const InstallAllPluginsButton = () => {
const { data: availablePlugins, isLoading: isLoadingAvailablePlugins } =
useGetAvailablePluginsQuery();
const [installPlugin, installationResult] = useInstallPluginMutation();
// How can I trigger a loading state in each "PluginInstallationButton" ?
const installAllPlugins = () => {
availablePlugins.forEach((plugin) => {
installPlugin({
pluginVersion: plugin.version,
pluginName: plugin.name,
pluginType: plugin.pluginType
});
});
};
return (<Button onClick={installAllPlugins} />)
} Ideally, I would be able to pass the |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
In this case, you'll have to track your loading state manually using the promises returned by the mutation triggers - no matter what you do, the hooks will only track the last mutation. |
Beta Was this translation helpful? Give feedback.
-
@phryneas Based on the tests I did, hooks do track multiple mutations as long as their What I ended up doing as a workaround:
I'm not sure if there's something that could be done by the library to fix this. Creating a slice to track mutation state when mutations can share state feels bad. Maybe an optional |
Beta Was this translation helpful? Give feedback.
In this case, you'll have to track your loading state manually using the promises returned by the mutation triggers - no matter what you do, the hooks will only track the last mutation.