New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

m-model-react

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

m-model-react

m-model-react is designed to be used with [m-model-core](https://www.npmjs.com/package/m-model-core) in the world of react. It provides several useful optimized hooks

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

m-model-react

m-model-react is designed to be used with m-model-core in the world of react. It provides several useful optimized hooks

For the rest of the docuemnt, assume that we have already created model with m-model-core and called it User

Hooks

useModelDocById

import React from "react";
import { useModelDocById } from "m-model-react";
const UserShortInfoComponent = ({ userId }: { userId: number }) => {
    const user = useModelDocById(User, userId);
    if (!user) {
        return <div>loading...</div>;
    }
    return (
        <div>
            {user.getFullname()}
        </div>
    );
};

useModelDocByQuery

import React, { useMemo }  from "react";
import { useModelDocById } from "m-model-react";
const UserShortInfoComponent = ({ firstname }: { firstname?: string }) => {
    const query = useMemo(() => {
        if (!firstname) return null;
        return { firstname }
    }, [firstname]);
    
    const user = useModelDocByQuery(User, query);
    if (!user) {
        return <div>loading...</div>;
    }
    return (
        <div>
            {user.getFullname()}
        </div>
    );
};

useModelDocsByIds

Similar to useModelDocById, just pass memoized array of ids and it will return array of model instances

useModelDocByQuery

Similar to useModelDocById. It will return array of model instances

useModelDocs

returns array of all instances of model

FAQs

Package last updated on 08 Jun 2020

Did you know?

Socket

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.

Install

Related posts