GithubHelp home page GithubHelp logo

oblosys / react-use-table-editor Goto Github PK

View Code? Open in Web Editor NEW
2.0 3.0 0.0 3.26 MB

React hook that provides dirty-tracking on table rows and cells.

Home Page: https://codesandbox.io/s/github/Oblosys/react-use-table-editor?file=/src/DemoTable.tsx

License: MIT License

JavaScript 7.35% HTML 4.02% TypeScript 80.50% CSS 3.98% Shell 4.15%
react table typed hooks editing dirty-tracking

react-use-table-editor's Introduction

React-use-table-editor npm version Build Status

The react-use-table-editor package exports a useTableEditor hook that maintains table-row state and provides cell-based update functions as well as dirty tracking for both cells and rows. The package also exports an EditableTable component that can be used with the hook result to easily build a table with custom cell-edit components that receive the cell state and dirty information via render-prop arguments.

The edit state is injected into each data row as a unique non-enumerable property, which allows other table packages to be used for building and rendering the table. The hook returns a number of strongly-typed edit functions for updating cell values, and adding, removing, or reverting rows.

A typical use case for this package is a page that offers batched editing for a list of server-based records. The table gets initialized with results from an api request, after which cells can be edited locally, and rows can be added or removed. Local changes are reflected in computed information like column sums, and can be reverted if necessary. A save button will send the modified rows to the api server and on success commit the changes to the local table.

To experiment with the package, you can open the demo on CodeSandbox.

Demo-table screenshot

Features

  • Dirty tracking of cell changes and added/removed rows
  • Local changes can be reverted per row
  • Strongly-typed cell update and equality functions
  • Light-weight package with zero dependencies
  • Designed to be used with other table packages for pagination, sorting, etc.

Usage

The package can be installed with

> npm install react-use-table-editor

Note that the it is still under heavy development, so breaking changes are to be expected, and documentation will be sparse until the model stabilizes.

The demo table app in this repository (available on CodeSandbox) can be run locally with

> git clone [email protected]:Oblosys/react-use-table-editor
> cd react-use-table-editor
> npm install
> npm start

To have the demo hot reload on changes to the package sources in /packages/react-use-table-editor/src/, link the package with

> npm run link

build it with

npm run build-watch

and launch the demo from a different terminal with

> npm start

react-use-table-editor's People

Contributors

oblosys avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar  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.