![Oracle Drags Its Feet in the JavaScript Trademark Dispute](https://cdn.sanity.io/images/cgdhsj6q/production/919c3b22c24f93884c548d60cbb338e819ff2435-1024x1024.webp?w=400&fit=max&auto=format)
Security News
Oracle Drags Its Feet in the JavaScript Trademark Dispute
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
@realm.io/react
Advanced tools
A better way to use Realm with React Native applications.
Setting up Realm in a React-Native application has been historically complex. Developers had been forced to develop their own methods to handle changes to Realm state. This can be error-prone an difficult to handle. This library alleviates that by providing hooks which return Realm data that is state aware. Any changes to the Realm data will cause components using the hook to rerender.
This library requires react-native
>= 0.59 and realm
>= 10.0.0
npm:
npm install @realm.io/react
yarn:
yarn add @realm.io/react
Create a Realm context object with createRealmContext
. It takes a Realm configuration and returns a RealmProvider and contextual hooks.
// RealmContext.tsx
import {createRealmContext} from '@realm.io/react';
class Task extends Realm.Object {
_id!: Realm.BSON.ObjectId;
description!: string;
isComplete!: boolean;
static generate(description: string) {
return {
_id: new Realm.BSON.ObjectId(),
description,
isComplete: false,
createdAt: new Date()
};
}
// To use a class as a Realm object type, define the object schema on the static property "schema".
static schema = {
name: 'Task',
primaryKey: '_id',
properties: {
_id: 'objectId',
description: 'string',
isComplete: {type: 'bool', default: false},
createdAt: 'date'
},
};
}
export const {RealmProvider, useRealm, useObject, useQuery} =
createRealmContext({schema: [Task.schema]});
Wrap the component needing access to Realm (possible your entire application) with the RealmProvider
componenet.
The RealmProvider
also accepts Realm configuration properties.
import {RealmProvider} from './createRealmContext';
function AppWrapper() {
if (!RealmProvider) {
return null;
}
return (
<RealmProvider path={"customPath"}>
<App />
</RealmProvider>
);
};
The hooks created by createRealmContext
can now be used by any child component.
function MyComponent({someId}){
const realm = useRealm();
const tasks = useQuery<Task>('Task');
const someObject = useObject<SomeObject>('Objects', someId);
// sort collection with useMemo
const sortedTasks = useMemo( () => tasks.sorted("createdAt"), [tasks])
// make sure the data is there
if(!tasks || !someObject){
return null
}
return ...
}
FAQs
React specific hooks and implementation helpers for Realm
The npm package @realm.io/react receives a total of 21 weekly downloads. As such, @realm.io/react popularity was classified as not popular.
We found that @realm.io/react demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 7 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Oracle seeks to dismiss fraud claims in the JavaScript trademark dispute, delaying the case and avoiding questions about its right to the name.
Security News
The Linux Foundation is warning open source developers that compliance with global sanctions is mandatory, highlighting legal risks and restrictions on contributions.
Security News
Maven Central now validates Sigstore signatures, making it easier for developers to verify the provenance of Java packages.