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.

zustand 3 milestones

See original GitHub issue

Let’s collect some,

  • Concurrent React, are we ready for it?
  • Simpler API?

currently

const [useStore, api] = create(set => ({ set, count: 0 }))

const count = useStore(state => state.count)

const count = api.getState().count
const unsub = api.subscribe(count => console.log(count), state => state.count)
api.setState({ count: 1 })

why not

const useStore = create(set => ({ set, count: 0 }))

const count = useStore(state => state.count)

const count = useStore.getState().count
const unsub = useStore.subscribe(count => console.log(count), state => state.count)
useStore.setState({ count: 1 })

vanilla users wouldn’t name it “useStore”

const api = create(set => ({ set, count: 0 }))
const count = api.getState().count

it would mean we’re now api compatible with redux without doing much.

with a little bit of hacking it could also be made backwards compatible by giving it a iterable property. i’ve done this before with three-fibers useModel which returned an array once, but then i decided a single value is leaner.

@JeremyRH

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:6
  • Comments:25 (11 by maintainers)

github_iconTop GitHub Comments

4reactions
JeremyRHcommented, Feb 14, 2020

Looks like a new React hook might solve this: https://github.com/reactjs/rfcs/pull/147

4reactions
timkindbergcommented, Dec 13, 2019

Another idea for clean api would be to return the api object and have the hook be a property on it.

const store = create(set => ({ set, count: 0 }))

const count = store.use(state => state.count)

const count = store.getState().count
const unsub = store.subscribe(count => console.log(count), state => state.count)
store.setState({ count: 1 })
Read more comments on GitHub >

github_iconTop Results From Across the Web

Mathieu A. on Twitter: "@0xca0a @dai_shi Thanks! We use zustand ...
zustand 3 milestones · Issue #71 · pmndrs/zustand. Let's collect some, Concurrent React, are we ready for it? Simpler API? currently const [useStore, ......
Read more >
Important Milestones: Your Baby By Three Years | CDC
Check the milestones your child has reached by the end of 3 years by completing a checklist with CDC's free Milestone Tracker mobile...
Read more >
Gemini 60 Milestone Cards Gift/ Baby Milestones/ Twins - Etsy
Zustand. Select an option, Ohne Mängel, Mit kleinen Mängeln [Sold out, waitlist available]. Please select an option. Returns & exchanges accepted.
Read more >
Customer reviews: Porsche Milestones - Amazon.com
Ein ganz tolles Buch für Porsche Liebhaber. Jedoch kam es in keinem neuwertigen Zustand an. Keine Folie um das Buch. Buchdeckel und Buchrücken...
Read more >
Same---Doppel CD 50 Golden Milestones Vol.3 - Musik - Atlaz
Musiktitel:50 Golden Milestones Vol.3.Produktart:cd.Genre:Rock. der gebraucht wurde, wie z.B. Gebrauchsspuren oder Risse.sich aber in einem guten Zustand ...
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