Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@lessondesk/react-table-context

Package Overview
Dependencies
Maintainers
6
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@lessondesk/react-table-context

Flexible Table Provider & Consumer

  • 1.2.0
  • Source
  • npm
  • Socket score

Version published
Maintainers
6
Created
Source

@lessondesk/react-table-context

package version package downloads standard-readme compliant package license make a pull request

Flexible Table Provider & Consumer

Table of Contents

Usage

import React from 'react'
import ReactDOM from 'react-dom'

import createTableContext from './react-table-context'

const Table = () => {
  const [Provider, Consumer] = createTableContext(async args => {
    console.log('args', args)

    const response = await fetch('https://jsonplaceholder.typicode.com/todos')
    const json = await response.json()

    return {
      meta: {
        count: json.length
      },
      data: json
    }
  })

  return <Provider>
    <div>
      <h1>Example Table</h1>
      <Consumer>
        {({
          page, // 0
          pageSize, // 10
          firstPage, // true
          isLoading, // false
          isEmpty, // false
          data, // Array[100]
          meta, // Object
          error, // null
          filters, // Object
          unappliedFilters, // Object
          sorting, // Object
          pageData, // Array[10]
          selected, // Array[0]
          search, //
          setSearch, // function () {}
          setPage, // function () {}
          setSorting, // function () {}
          setPageSize, // function () {}
          refresh, // function () {}
          setSelected, // function () {}
          toggleSelectAll, // function () {}
          setFilters, // function () {}
          setUnappliedFilters, // function () {}
          applyFilters // function () {}
        }) => {
          console.log('data', data)
          return <table>
            <thead>
              <tr>

                <th>ID</th>
                <th>Title</th>
                <th>Completed</th>
              </tr>
            </thead>
            <tbody>
              {pageData.map(({ id, title, completed }) => {
                return <tr key={id}>
                  <td>{id}</td>
                  <td>{title}</td>
                  <td>{completed ? 'Yes' : 'Nope'}</td>
                </tr>
              })}
            </tbody>
          </table>
        }}
      </Consumer>
    </div>
  </Provider>
}

function App () {
  return (
    <div className='App'>
      <Table />
    </div>
  )
}

const rootElement = document.getElementById('root')
ReactDOM.render(<App />, rootElement)

Install

This project uses node and npm.

$ npm install @lessondesk/react-table-context
$ # OR
$ yarn add @lessondesk/react-table-context

Contribute

  1. Fork it and create your feature branch: git checkout -b my-new-feature
  2. Commit your changes: git commit -am "Add some feature"
  3. Push to the branch: git push origin my-new-feature
  4. Submit a pull request

License

MIT

Keywords

FAQs

Package last updated on 14 Jul 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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc