Cannot register spotlight action in an effect
See original GitHub issueWhat package has an issue
Describe the bug
If you try to register new actions in an useEffect
, this doesn’t work. If you pass spotlight
as the useEffect dependency, this is run forever. also if you limit to registerActions
and removeActions
which probably are incorrectly created and are not callbacks created through useCallback
.
The idea is this:
const spotlight = useSpotlight();
useEffect(() => {
console.log("register");
spotlight.registerActions([
{
id: "act1",
title: "Action",
onTrigger: () => {}
}
]);
return () => {
console.log("remove");
spotlight.removeActions(["act1"]);
};
// Try to correctly pass spotlight as dependency here
}, []);
An use case for this is to register and de-register actions based on external events. e.g. an action to mute/unmute the microphone based on the mute state.
In which browser did the problem occur
Any
If possible, please include a link to a codesandbox with the reproduced problem
https://codesandbox.io/s/reverent-leftpad-6i6fkz
Do you know how to fix the issue
No
Are you willing to participate in fixing this issue and create a pull request with the fix
No
Possible fix
This probably happen because everytime the children of SpotlightProvider change, the initial actions are re-set
Issue Analytics
- State:
- Created a year ago
- Comments:7 (5 by maintainers)
Top Results From Across the Web
How to Fix It When Windows Spotlight Is Not Working on ...
Select the Start menu, type Settings, and choose the Settings app. Select Personalization > Lock Screen.
Read more >Configure Windows Spotlight on the lock screen
Windows Spotlight is an option for the lock screen background that displays different background images on the lock screen.
Read more >The Spotlight Effect and Social Anxiety - Verywell Mind
The spotlight effect occurs when we overestimate how much others notice us. It may occur if you have social anxiety. Learn more about...
Read more >Spotlight Effect: Definition, Examples, and Experiments
Something called the spotlight effect helps explain why you don't need to worry about your faux pas lingering in anyone's memory (except ...
Read more >Spotlight cannot find Maps app in latest Ventura 13.1 - Reddit
Yes, deleting com.apple.Spotlight.plist followed by a reboot seems to have resolved it. Thank You!
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
PR #1085 introduced behavior to update the actions whenever the actions prop to
SpotlightProvider
changes.@ramiel because you are passing an unmemoized array as the actions prop, when the provider re-renders it thinks your actions have changed and updates actions with the empty array. Dependency checks are always shallow comparisons; the two empty arrays from each re-render are NOT equal. Memoizing the array fixes your sandbox example: https://codesandbox.io/s/vibrant-jennings-ioy752
Fixed in 5.1.3