@rattus-orm/react-mobx
TypeScript icon, indicating that this package has built-in type declarations

0.2.2 • Public • Published

Rattus ORM

bundle size npm version (core)

Rattus ORM – React MobX

React MobX data provider and helpers for Rattus ORM

Contents

  1. ReactMobxDataProvider;
  2. <RattusProvier /> component;
  3. Hooks: useRattusContext, useRepository.

Installation

Use your favorite package manager. For example, yarn:

yarn add @rattus-orm/core @rattus-orm/react-mobx mobx mobx-react-lite

Basic usage

import React from 'react'
import ReactDOM from 'react-dom/client'
import App from './App.tsx'
import './index.css'
import { RattusProvider } from "@rattus-orm/react-mobx";

ReactDOM.createRoot(document.getElementById('root')!).render(
  <React.StrictMode>
    <RattusProvider>
      <App />
    </RattusProvider>
  </React.StrictMode>,
)
export class User extends Model {
    public static entity = 'user'
    
    @Uid()
    public id: string
    
    @Str()
    public email: string
}
import { useEffect } from 'react'
import { useRepository } from "@rattus-orm/react-mobx";
import { User } from "./models/User.ts";
import { observer } from 'mobx-react-lite'

const App = observer(() => {
  const { query, save } = useRepository(User)
  const user = query().where('id', '1').first()

  useEffect(() => {
    save({ id: '1', email: 'test@test.com' })
  }, [])

  if (!user) {
    return ''
  }

  return (
    <>
      <p>{user.email}</p>
      <button type="button" onClick={() => save({ id: '1', email: 'updated@test.com' })}>Update email</button>
    </>
  )
})

Documentation

For detailed docs please read documentation website.

Contributing

Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, and the process for submitting pull requests.

Package Sidebar

Install

npm i @rattus-orm/react-mobx

Weekly Downloads

3

Version

0.2.2

License

MIT

Unpacked Size

112 kB

Total Files

6

Last publish

Collaborators

  • lyohaplotinka