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

use-exportable-csv

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

use-exportable-csv

React hook for using exportable csv in convenient way

latest
Source
npmnpm
Version
1.0.2
Version published
Weekly downloads
178
-38.19%
Maintainers
1
Weekly downloads
 
Created
Source

use-exportable-csv npm npm downloads

React hook for downloading csv in convenient way.

  • your json-like data (or 2D array) in converted into csv (with options You provide: delimiter, headers, BOM mask) and on top of this, blob is generated
  • blob is available under object URL, which is returned from hook
  • each time you change your data/options, object URL is updated (old one is unbound from document)
  • link can be used as anchor tag attribute - href

Usage

Check also my blog post how to deal with CSV exports

function Component() {
  const [data, setData] = useState([])

  useEffect(() => {
    fetch('https://jsonplaceholder.typicode.com/todos')
      .then((res) => res.json())
      .then(setData)
  }, [])

  const options = { bom: true }
  const csvLink = useExportableCSV(data, options)

  return (
    <div className="xyz">
      (...)
      <a className="link" href={csvLink} download="data.csv">
        CSV download
      </a>
      (...)
    </div>
  )
}

Live Example

API

type CSVDelimiter = ',' | ';'
type Options = Partial<{
  bom: boolean
  delimiter: CSVDelimiter
  headers: string[]
}>
type Value = string | number | bigint | boolean | null
type Content = Value[][] | Record<string, Value | Value[]>[]

useExportableCSV() call

const link: string = useExportableCSV(content: Content, options: Options)

Keywords

react

FAQs

Package last updated on 19 Oct 2023

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