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

Derive state from localStorage #54

Open
ivan-unfolds opened this issue Oct 28, 2022 · 0 comments
Open

Derive state from localStorage #54

ivan-unfolds opened this issue Oct 28, 2022 · 0 comments

Comments

@ivan-unfolds
Copy link

ivan-unfolds commented Oct 28, 2022

You don't need this state, you can just derive it from what's in local storage

const [itemsInBasket, setItemsInBasket] = useState(0);

So something like

const itemsInBasket = JSON.parse(localStorage.getItem("basket")).length

I spoke last week about having as little state as possible and deriving data you need for your UI from the it. This is an example of that, let me know if that makes sense!

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

No branches or pull requests

1 participant