You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wonder if similar to local state sharing a global selection state could be held with swr.
// I have a button that checks if the current selection offers a "delete" functionconstFloatingDeleteButton=()=>{const{ selection }=useSelection()if(typeofselection?.delete==="function"){return<Buttontitle="Delete"onPress={selection.delete}/>}returnnull}// And I have a page that offers a selectionconstItemPage()=>{const{ items, deleteItems }=useItems()useSelection(items&&{delete: deleteItems})}
When the ItemPage is unmounted, the previous selection should be active again.
When useSelection is called without an argument, then the current selection should not be altered.
I am currently using this in react-navigation screens and it somehow always displays the delete button, even when no selection should be set.
I also have a dependency problem, when I want to refer to the outer items like this:
Then items is undefined. I guess I have to add some dependency array to my hook to get the current reference to the items when the delete function is called.
I noticed that calling mutate(undefined, false) on unmount does not actually change anything but calling with null does.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
I wonder if similar to local state sharing a global selection state could be held with swr.
I have implemented this hook:
When the
ItemPage
is unmounted, the previous selection should be active again.When
useSelection
is called without an argument, then the current selection should not be altered.I am currently using this in react-navigation screens and it somehow always displays the delete button, even when no selection should be set.
I also have a dependency problem, when I want to refer to the outer items like this:
Then items is
undefined
. I guess I have to add some dependency array to my hook to get the current reference to theitems
when thedelete
function is called.I noticed that calling
mutate(undefined, false)
on unmount does not actually change anything but calling withnull
does.Does this make sense?
Beta Was this translation helpful? Give feedback.
All reactions