For the complete documentation index, see llms.txt. This page is also available as Markdown.

Input Helpers

Various helpers related to input specific functionality.

Source code is hosted on GitHub

yarn add @corets/input-helpers

Quick Start

Prompt user to select a file and send it to a server:

import React from "react"
import { selectFile } from "@corets/input-helpers"
import axios from "axios"

const Example = () => {
  const handleSelectFile = async () => {
    const file = await selectFile()
    
    if ( ! file) return
    
    submitFile(file)
  }
  
  const submitFile = async (file: File) => {
    const formData = new FormData()
    formData.append('file', file)
    
    await axios.post(`/endpoint`, formData, {
      headers: { 'content-type': 'multipart/form-data' },
    })
  }
  
  return <button onClick={handleSelectFile}/>
}

Prompt user to select a file and show a preview:

selectFile()

Prompt user to select one file:

selectFiles()

Prompt user to select multiple files:

selectFileOfType()

Prompt user to select a file of a specific type:

Read more about file types here.

selectFilesOfType()

Prompt user to select multiple files of a specific type:

Last updated

Was this helpful?