nostr is great because it's permissionless for developers as well as users. No API keys needed!
Soooo I'm learning to build a nostr client for fun and maybe one day I'll build something useful
And I'll sporadically post resources which I've found helpful along the way and ramblings which will mostly revolve around React as it's the framework I'm learning with
I'm using Vite for starting a project https://vitejs.dev/
npm create vite@latest
npm run dev
Job done
This tutorial using the nostr-tools library is clear and well paced
https://www.youtube.com/watch?v=O9bzEvv-oFE
The nostr-tools library: https://github.com/nbd-wtf/nostr-tools
Later I'll try the NDK library by nostr:npub1l2vyh47mk2p0qlsku7hg0vn29faehy9hy34ygaclpn66ukqp3afqutajft which is higher level and does nice things with relays and uses nostr-tools internally: https://github.com/nostr-dev-kit/ndk
If like me you're new to this probably the first big (but fun!) hurdle will be the general social media challenge of working with streams of events. Not the nostr protocol itself which is dead simple.
Streams of events which affect other streams of events which affect your application state which affects your streams.
It's very easy to create an INFINITE LOOP
The first indication is the laptop fan preparing for takeoff
The second is the console log showing the relays spammed with hundreds of requests... to which they are remarkably tolerant
Working with event streams in React probably means using useEffect
There's a tendency to overuse useEffect because of not realizing the purpose of useEffect is synchronizing streams of events ("effects") i.e. just what we need it for and no more
This really is an excellent talk, both on useEffect and handling events in React in general
https://www.youtube.com/watch?v=bGzanfKVFeU
... I don't think a state machine is a practical fit to this particular problem but I might be wrong. One approach I'd like to try which is literally made for working with event streams is RxJS https://rxjs.dev/
Sometimes you have to do things which are ugly and you need to forgive yourself for doing ugly things because at the end of the day the ugly thing is solving the problem...
useEffect creates an infinite loop if passed vector dependencies because it does a shallow check on referential equality. Various workarounds are suggested including useMemo and useRef. Good discussion here:
https://www.youtube.com/watch?v=dH6i3GurZW8
I like doing JSON.stringify on the dependencies as it makes it abundantly clear what the purpose is
And TypeScript makes it safe to do JSON.stringify on Map keys 😃
Project status: amazed to see events come in. It's like building a crystal radio.