Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

usePreferences behavior is unexpected when used outside of Configurable #9526

Closed
KilianB opened this issue Dec 14, 2023 · 1 comment · Fixed by #9537
Closed

usePreferences behavior is unexpected when used outside of Configurable #9526

KilianB opened this issue Dec 14, 2023 · 1 comment · Fixed by #9537
Labels

Comments

@KilianB
Copy link

KilianB commented Dec 14, 2023

What you were expecting:

I would have expected the hook usePreferences to save a value inside the RaStore.preferences path.

If usePreferences is not to be used outside of a Configurable (which in my opinion it should be based on the name), at least a a warning should be printed to the console if the PreferenceKeyContext is not provided or empty.

What happened instead:

The key value forwarded to the setItem function in the store is empty, resulting in a value being set for RaStore. no matter what the actual key is.

image

Steps to reproduce:

  • Use the following code snipped outside of a Configurable component
   //Does not work but should be identical to the hook below
   const [showExpertView, setShowExpertView] = usePreferences(
    "expertView",
    false,
  );
  
 //Works
  const [showExpertView, setShowExpertView] = useStore(
    "preferences.expertView",
    false,
  );
@fzaninotto
Copy link
Member

you're right, if usePreferences is used outside of the right context, we should throw an error inviting to use useStore instead.

Would you like to open a PR about it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants