Giter VIP home page Giter VIP logo

Comments (2)

emab avatar emab commented on August 17, 2024

I've been playing around with this myself, as RxDB looks great and having better type support via hooks would be great.

https://github.com/emab/rxdb-hooks-todo/blob/dcd4f8a6c60ee9898db075f1cff2cc5396fa0a1f/src/Todo.tsx

Here's an example Todo application, with some hooks. The typing right now is baked into the hooks - so thinking of a way of handling this would be great.

In Redux you often export your own versions of a useSelector hook, providing your store type with them:

import { useDispatch, useSelector, useStore } from 'react-redux'
import type { AppDispatch, AppStore, RootState } from './store'

// Use throughout your app instead of plain `useDispatch` and `useSelector`
export const useAppDispatch = useDispatch.withTypes<AppDispatch>()
export const useAppSelector = useSelector.withTypes<RootState>()
export const useAppStore = useStore.withTypes<AppStore>()

I'm thinking if I take what I have now and apply this methodology we should end up with nicely typed hooks.

The next step would be getting them more feature complete - so maybe doing this approach in this repo would be better.

from rxdb-hooks.

TimurKr avatar TimurKr commented on August 17, 2024

Hey @emab, I am glad someone is still looking into this.

I got this working really well in my repo, but I never got around to actually making a PR and I am not working on the project where I did this already, so I guess I never will... Maybe someone else could take it over the finish line, or at least be inspired by my approach, so here is the repo. Check out the /rxdb-hooks/hooks.tsx file for the definition of the typed hook builder and the rxdb/db.tsx for the usage.

The project is also using supabase replication, so if that is your case, there is a custom script that introspects your supabase and generates the schemas for you.

from rxdb-hooks.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.