React MobX data provider and helpers for Rattus ORM
- ReactMobxDataProvider;
-
<RattusProvier />
component; - Hooks:
useRattusContext
,useRepository
.
Use your favorite package manager. For example, yarn:
yarn add @rattus-orm/core @rattus-orm/react-mobx mobx mobx-react-lite
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>
</>
)
})
For detailed docs please read documentation website.
Contributions are welcome! Please read our Contributing Guide for details on our code of conduct, and the process for submitting pull requests.