question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript type WriteOnlySelectorOptions<T> ?

See original GitHub issue

Hello ! 👋 I would like to know if the implementation of a WriteOnlySelectorOptions<T> is planned. I would like to use a selector to only Write and not Read values.

If this case we should have this i think :

export interface WriteOnlySelectorOptions<T> {
    set: (
        opts: {
            set: SetRecoilState;
            get: GetRecoilValue;
            reset: ResetRecoilState;
        },
        newValue: T | DefaultValue,
    ) => void;
}

Currently we have only this :

export interface ReadWriteSelectorOptions<T> extends ReadOnlySelectorOptions<T> {
    set: (
        opts: {
            set: SetRecoilState;
            get: GetRecoilValue;
            reset: ResetRecoilState;
        },
        newValue: T | DefaultValue,
    ) => void;
}

I get errors in the image above because i must use the get inside my selector (but for my case i don’t need it !)

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:1
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
PierreMouchancommented, Jun 16, 2020

Thank you ! Works like a charm !

0reactions
drarmstrcommented, Jun 16, 2020

Actually, you can also avoid useRecoilCallback() entirely:

const [currentTheme, setTheme] = useSetRecoilState(currentThemeStore);
const toggleCurrentTheme = useCallback(() => {
  const newTheme = currentTheme === 'light' ? 'dark' : 'light';
  if (newTheme === 'dark') {
      document.body.classList.remove('body-light');
      document.body.classList.add('body-dark');
      setTheme('dark');
  } else {
      document.body.classList.remove('body-dark');
      document.body.classList.add('body-light');
      setTheme('light');
    }
    // Set colorsStore according to new theme
    set(colorsStore, setColorsObject(newTheme));
    // Set CSS variables according to new theme
    setColorsVariables(newTheme);
    // Set preference into localStorage
    window.localStorage.setItem('color-mode', newTheme);
});
Read more comments on GitHub >

github_iconTop Results From Across the Web

Readonly - TypeScript Deep Dive - Gitbook
TypeScript's type system allows you to mark individual properties on an interface as readonly . This allows you to work in a functional...
Read more >
TypeScript - ReadOnly Class Properties - TutorialsTeacher
TypeScript introduced readonly keyword which makes a property as read-only in the class, type or interface.
Read more >
Documentation - Utility Types - TypeScript
Constructs a type with all properties of Type set to readonly , meaning the properties of the constructed type cannot be reassigned.
Read more >
TypeScript and the ReadOnly option - Daily Dev Tips
Let's look at the readonly property in TypeScript and how we can add and remove ... It works by prefixing the type with...
Read more >
Typescript creating Object Type from Readonly Array
Access each whole individual object with only [number] , then separately extract the name property (assert that it'll be the key with as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found