Bunlong / react-papaparse

react-papaparse is the fastest in-browser CSV (or delimited text) parser for React. It is full of useful features such as CSVReader, CSVDownloader, readString, jsonToCSV, readRemoteFile, ... etc.
https://react-papaparse.js.org
MIT License
363 stars 60 forks source link

feat: CSVReader typescript improvements | style object type casting refactoring #150

Open berkinanik opened 1 year ago

berkinanik commented 1 year ago

resolves #149

might be considered as a breaking change proposal

Important parts are under: useCSVReader.tsx

berkinanik commented 1 year ago
berkinanik commented 1 year ago

js-docs for useCSVReader hook

image


useCSVReader hook returns the properly typed CSVReader component

image

generic element type provides proper event handler, event and children render function's arguments proper types

image

first generic type is the parsed result's data type which affects return result type


results object is now properly typed as ParseResult and thanks to properly type CSVReader and the hook. Its type is inferred using the handler onUploadAccepted functions argument type

image

image


Thanks to properly typed children render function arguments and all the return types of those argument methods, now children render function is properly typed and proper types are inferred

image

image

Inferred types of those renderer func arguments, all that methods return proper props of the elements for the spread operation

image

image

image

image

image

image


All the events themselves and the handler function types are properly inferred

image

image

image

image

statusunknown418 commented 1 year ago

why hasn't this been merged yet :(

antoinerousseau commented 1 year ago

Thanks @berkinanik ❤️

@Bunlong can we merge this? it's awesome

spencemc commented 1 year ago

This would be awesome to merge! @Bunlong

jjjjonathan commented 1 year ago

Any blocker here? @Bunlong would love to have this