Giter Site home page Giter Site logo

plant's Introduction

Plant

通过标准化的API来解决前端增删改查的问题

Install

# or yarn 
$ npm install plant

Usage

直接使用

import { usePlant } from '@sensoro/plant';

const model = {
  fetch: () =>
    Promise.resolve({
      code: 0,
      data: {
        list: [{ id: 1 }, { id: 2 }, { id: 3 }],
        total: 3,
      },
    }),
};

export default () => {
  const { allIds, fetch } = usePlant(model);
  React.useEffect(() => {
    fetch();
  }, []);
  console.log('allIds = ', allIds);
  return <div className={styles.normal}>Hello Plant!</div>;
};

跨组件使用(不作为plant的一个主要功能,但是封装了简单的context,作为一种思路)

import React from 'react';
import styles from './index.css';
import { createPlant, usePlantContext, Plant } from '@sensoro/plant';

const plant = createPlant();

const model = {
  fetch: () =>
    Promise.resolve({
      code: 0,
      data: {
        list: [{ id: 1 }, { id: 2 }, { id: 3 }, { id: 4 }],
        total: 4,
      },
    }),
};

const Demo: React.FC = () => {
  const { allIds, byId, fetch, loading } = usePlantContext(plant);
  React.useEffect(() => {
    fetch();
  }, []);
  console.log('allIds = ', allIds, byId);
  return <div>demo</div>;
};

export default () => {
  return (
    <Plant model={model} plant={plant}>
      <div className={styles.normal}>
        <Demo />
      </div>
    </Plant>
  );
};

Options

TODO

LICENSE

MIT

plant's People

Contributors

jqxismygit avatar

Stargazers

Alva Greason avatar

Watchers

James Cloos avatar

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.