I have the following problem. How should I show an error to the user using a zustand for storing my data? I have a function showError
that I am using through my react application to show an error. The idea is I pass an error message and a toast is shown to the user.
ItemsStore.ts
try {
const currentItem = await getItem(itemId);
set(state => {
state.items = [...state.items, currentItem]
});
} catch (error){
// Example error: Item doesn't exist.
// How to show my error to the user
// I can't use my showError function here,
// it should be inside a component to not
// break the rules of hooks
}
const MyComponent = () => {
const items = useItemStore(state=>state.items);
// I don't have an access what happens intern in my store
// If error occurs the items are an empty array.
}