React

๊ด€๋ฆฌ์ž๋‹จ ํ•„์ˆ˜ ๊ธฐ๋Šฅ react-csv ํ™œ์šฉํ•œ CSV ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ

martinooo 2024. 8. 22. 17:09

react-csv

 

 

 

๐Ÿคท‍โ™‚๏ธ react-csv๋ž€?


๋ฆฌ์•กํŠธ๋กœ ๊ด€๋ฆฌ์ž๋‹จ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋‹ค ๋ณด๋ฉด ์—‘์…€ ํŒŒ์ผ, CSV ํŒŒ์ผ ๋“ฑ๋“ฑ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ด ํ•„์š”ํ•ฉ๋‹ˆ๋‹ค.

 

project

 

์œ„์™€ ๊ฐ™์ด ๊ธฐ๊ฐ„๋ณ„, ์œ ํ˜•๋ณ„๋กœ ํ†ต๊ณ„ํ•œ ๋ฐ์ดํ„ฐ๋“ค์„ CSV ํŒŒ์ผ๋กœ ๋‹ค์šด๋กœ๋“œ ํ•ด์ฃผ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.

 

 

 

๐Ÿคท‍โ™‚๏ธ react-csv ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ ์„ ํƒํ•œ ์ด์œ 


๋ณดํ†ต์€ ์„œ๋ฒ„์—์„œ ๋ฐ์ดํ„ฐ๋ฅผ ์ฒ˜๋ฆฌํ•ด ํŒŒ์ผ์„ ๋งŒ๋“ค์–ด ํ”„๋ก ํŠธ์—์„œ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๋Š” ๋ฐฉ์‹์ด ๋งŽ์ด ์‚ฌ์šฉ๋ฉ๋‹ˆ๋‹ค.

 

๊ทธ๋Ÿฌ๋‚˜ ์ €๋Š” ์„œ๋ฒ„์—์„œ ํŒŒ์ผ์„ ์ฒ˜๋ฆฌํ•˜๊ธฐ๋ณด๋‹ค ํ”„๋ก ํŠธ์—์„œ ์ง์ ‘ CSV ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œํ•˜๋Š” ๊ฒƒ์ด ๋” ํšจ์œจ์ ์ด๋ผ๊ณ  ํŒ๋‹จํ•˜์—ฌ react-csv ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์„ ํƒํ•œ ์ด์œ ์ค‘์— ํ•˜๋‚˜๋Š” ์ฃผ๊ฐ„ ๋‹ค์šด๋กœ๋“œ ํšŸ์ˆ˜๋„ 375,547 ์ด๋ฉฐ ๊ฐ€์žฅ ์ตœ๊ทผ ๊นŒ์ง€ gitํ™œ๋™์ด ์›ํ™œํ–ˆ์Šต๋‹ˆ๋‹ค.

 

recat-csv ๊ณต์‹ ์‚ฌ์ดํŠธ

https://www.npmjs.com/package/react-csv

 

react-csv

Build CSV files on the fly basing on Array/literal object of data . Latest version: 2.2.2, last published: 3 years ago. Start using react-csv in your project by running `npm i react-csv`. There are 307 other projects in the npm registry using react-csv.

www.npmjs.com

 

types/react-csv

https://www.npmjs.com/package/@types/react-csv

 

@types/react-csv

TypeScript definitions for react-csv. Latest version: 1.1.10, last published: 8 months ago. Start using @types/react-csv in your project by running `npm i @types/react-csv`. There are 38 other projects in the npm registry using @types/react-csv.

www.npmjs.com

 

๐Ÿคท‍โ™‚๏ธ react-csv ๋‹ค์šด๋กœ๋“œ


react-csv ๋‹ค์šด๋กœ๋“œ๋Š” ๊ฐ„๋‹จํ•ฉ๋‹ˆ๋‹ค.

// npm 
npm i react-csv --save

// pnpm 
pnpm i react-csv 

// yarn
yarn add react-csv

// typescript
npm i --save @types/react-csv

 

ํ”„๋กœ์ ํŠธ์— ๋งž๋Š” ํŒจํ‚ค์ง€๋กœ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์œผ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

๐Ÿคท‍โ™‚๏ธ react-csv ๊ธฐ๋Šฅ


react-csv ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” 2๊ฐ€์ง€ ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•ฉ๋‹ˆ๋‹ค.

  1. CSVLink: ์ด ๊ธฐ๋Šฅ์€ ํด๋ฆญ์„ ํ•˜๋ฉด ์—‘์…€ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์„ ์ˆ˜ ์žˆ๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค.
  2. CSVDownload: ์ด ๊ธฐ๋Šฅ์€ ๋งˆ์šดํŠธ ๋ ๋•Œ ์ž๋™์œผ๋กœ ํŒŒ์ผ์ด ๋‹ค์šด๋กœ๋“œ ๋˜๋Š” ๊ธฐ๋Šฅ์ž…๋‹ˆ๋‹ค. (๋งˆ์šดํŠธ ๋ ๋•Œ ํ•„์ˆ˜์ ์œผ๋กœ ํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์•„์•ผ๋˜๋Š”๊ฒŒ ์•„๋‹ˆ๋ผ๋ฉด ๊ถŒ์žฅ๋˜์ง€ ์•Š์Šต๋‹ˆ๋‹ค.)

 

 

๐Ÿคท‍โ™‚๏ธ CSVLink ๊ธฐ๋Šฅ ์˜ต์…˜


  • data: csv ํŒŒ์ผ์—์„œ ๋ฐ์ดํ„ฐ๊ฐ€ ๋“ค์–ด๊ฐ€๋Š” ๋ถ€๋ถ„์ด๋ฉฐ ๋ฐ์ดํ„ฐ๋Š” ์ด์ค‘๋ฐฐ์—ด, ๊ฐ์ฒด ๋ฐฐ์—ด ํ˜น์€ ๋ฌธ์ž์—ด ํ˜•์‹์œผ๋กœ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค..
  • header: csv ํŒŒ์ผ์—์„œ ํ•„๋“œ๋ฅผ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์œผ๋ฉฐ label๊ณผ key๊ฐ’์„ ์ค„ ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • filename: ๋‹ค์šด๋กœ๋“œ ๋ฐ›๋Š” csv ํŒŒ์ผ ์ด๋ฆ„์„ ์ง€์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.
  • onClick: ๋งํฌ๋ฅผ ํด๋ฆญํ•  ๋•Œ ๋™๊ธฐ / ๋น„๋™๊ธฐ์ ์œผ๋กœ ์—ฌ๋Ÿฌ ์ž‘์—…์„ ์ˆ˜ํ–‰ํ•˜๊ณ ์ž ํ•  ๋•Œ ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

์‚ฌ์šฉ๋ฒ• ์˜ˆ์ œ

const headers = [
  { label: "First Name", key: "firstname" },
  { label: "Last Name", key: "lastname" },
  { label: "Email", key: "email" }
];

const data = [
  { firstname: "Ahmed", lastname: "Tomi", email: "ah@smthing.co.com" },
  { firstname: "Raed", lastname: "Labes", email: "rl@smthing.co.com" },
  { firstname: "Yezzi", lastname: "Min l3b", email: "ymin@cocococo.com" }
];

<CSVLink 
  data={data} 
  headers={headers} 
  filename={'CSV ๋ฐ์ดํ„ฐ'}
  onClick={() => {
    console.log("๋งํฌ ํด๋ฆญํ•จ");
  }}
  >
  Download me
</CSVLink>;

 

์ฝ”๋“œ์—์„œ ๋ณด๋Š” ๊ฒƒ์ฒ˜๋Ÿผ header์— ํ•„๋“œ๋ฅผ ์…‹ํŒ…ํ•  ์ˆ˜ ์žˆ๊ณ  ๋ฐ์ดํ„ฐ๋ฅผ ๊ฐ์ฒด ๋ฐฐ์—ด๋กœ ์…‹ํŒ…ํ•  ํ•ด์„œ ์›ํ•˜๋Š” ๋ฐ์ดํ„ฐ๋ฅผ ๋ณผ์ˆ˜ ์žˆ๋„๋ก CSV ํŒŒ์ผ์„ ๋งŒ๋“ค์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

CSVLink onClick ์˜ˆ์ œ

const headers = [
  { label: "First Name", key: "firstname" },
  { label: "Last Name", key: "lastname" },
  { label: "Email", key: "email" }
];

const data = [
  { firstname: "Ahmed", lastname: "Tomi", email: "ah@smthing.co.com" },
  { firstname: "Raed", lastname: "Labes", email: "rl@smthing.co.com" },
  { firstname: "Yezzi", lastname: "Min l3b", email: "ymin@cocococo.com" }
];

<CSVLink 
  data={data} 
  headers={headers} 
  filename={'CSV ๋ฐ์ดํ„ฐ'}
  onClick={() => {
        if (confirm('csvํŒŒ์ผ์„ ๋‹ค์šด๋กœ๋“œ ๋ฐ›๊ฒ ์Šต๋‹ˆ๊นŒ?')) {
          return true;
        } else {
          return false;
        }
   }}
  >
  Download me
</CSVLink>;

 

๋‹ค์šด๋กœ๋“œ ์ „์— ํ™•์ธ ์ฐฝ์„ ๋„์›Œ, ํ™•์ธ์„ ๋ˆ„๋ฅด๋ฉด true, ์ทจ์†Œ๋ฅผ ๋ˆ„๋ฅด๋ฉด false๋ฅผ ๋ฐ˜ํ™˜ํ•˜๋„๋ก ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

alert

 

react-csv ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๋ฐ›์€ ํŒŒ์ผ

excel

 

๐Ÿคท‍โ™‚๏ธ ๋งˆ์ง€๋ง‰์œผ๋กœ


react-csv ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋ฅผ ์‚ฌ์šฉํ•ด ํ”„๋ก ํŠธ์—”๋“œ์—์„œ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ–ˆ์Šต๋‹ˆ๋‹ค.

 

์ด ๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ๋Š” ๋‘ ๊ฐ€์ง€ ์ฃผ์š” ๊ธฐ๋Šฅ์„ ์ œ๊ณตํ•˜๋ฉฐ, ์ƒํ™ฉ์— ๋งž๊ฒŒ ์„ ํƒํ•ด ์‚ฌ์šฉํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

ํŠนํžˆ CSVLink๋Š” ๋‹ค์–‘ํ•œ ์˜ต์…˜์„ ์ œ๊ณตํ•˜์—ฌ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ๋ฅผ ์‰ฝ๊ฒŒ ์ปค์Šคํ„ฐ๋งˆ์ด์ง•ํ•  ์ˆ˜ ์žˆ์–ด ๊ฐ„ํŽธํ•˜๊ฒŒ ์—‘์…€ ํŒŒ์ผ ๋‹ค์šด๋กœ๋“œ ๊ธฐ๋Šฅ์„ ๊ตฌํ˜„ํ•  ์ˆ˜ ์žˆ์Šต๋‹ˆ๋‹ค.

 

 


 

์žฌ๋ฐŒ๋Š” ์˜ค๋Š˜์˜ ๋ ๋ณ„ ์šด์„ธ ๋ณด๊ณ  ๊ฐ€์„ธ์š”! 

 

 

https://cometruedream.tistory.com/247

 

[React] Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผ className ์ปค์Šคํ…€

๐Ÿคท‍โ™‚๏ธ Tailwind ํ•œ์ค„, ๋‘์ค„, ์„ธ์ค„ ํšจ๊ณผํ”„๋กœ์ ํŠธ ์ง„ํ–‰์ค‘ ๋ฐฐ๋„ˆ ๋งํฌ์— URL ๊ธธ์ด๊ฐ€ ๋„ˆ๋ฌด ๊ธธ์–ด์„œ 3์ค„ ํšจ๊ณผ ์ฒ˜๋ฆฌ๋ฅผ ํ•ด์•ผ ํ–ˆ์Šต๋‹ˆ๋‹ค. React + Tailwind CSS ์…‹ํŒ…๋œ ํ”„๋กœ์ ํŠธ ์—ฌ์„œ CSS ํŒŒ์ผ & style ํƒœ๊ทธ๋ฅผ ์‚ฌ์šฉํ•˜

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/243

 

NestJS Lifecycle (์ƒ๋ช…์ฃผ๊ธฐ) ๊ฐœ๋…

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œ Nest JS ๊ฐœ๋…?Nest JS๋Š” Node JS ๊ธฐ๋ฐ˜์œผ๋กœ ํ•œ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ํ”„๋ ˆ์ž„์›Œํฌ ์ž…๋‹ˆ๋‹ค. ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ๋Š” ์ƒ๋‹นํžˆ ์˜ค๋žซ๋™์•ˆ Express ๊ธฐ๋ฐ˜์œผ๋กœ ์„œ๋ฒ„ ์–ดํ”Œ๋ฆฌ์ผ€์ด์…˜ ๊ฐœ๋ฐœ์—์„œ ์••๋„์ ์ธ ์ 

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/242

 

๋ฆฌ์•กํŠธ Vite Proxy ํ™œ์šฉํ•œ CORS ์˜ค๋ฅ˜ ํ•ด๊ฒฐ

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋ก ํŠธ์—”๋“œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ต์— ๋Œ€ํ•ด์„œ ๊ณต๋ถ€๋ฅผ ํ•˜๊ณ  ๊ธ€์„ ๋ณด์‹œ๋ฉด ๋” ๋งŽ์€ ๋„์›€์ด ๋ฉ๋‹ˆ๋‹ค^^ํ”„๋ก ํŠธ์—”๋“œ ๊ฐœ๋ฐœ์„ ์œ„ํ•œ ๋ฒˆ๋“ค๋Ÿฌ ๊ฐœ๋…๊ณผ webpack vs vite ๋น„๊ตhttps://comet

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/241

 

React ํด๋”๊ตฌ์กฐ FSD ๊ธฐ๋Šฅ ๋ถ„ํ™œ ์„ค๊ณ„ ์•„ํ‚คํ…์ฒ˜

๐Ÿคท‍โ™‚๏ธ ๋ณธ๋ก ์— ์•ž์„œํ”„๋กœ์ ํŠธ๋ฅผ ์‹œ์ž‘ํ•˜๊ธฐ์— ์•ž์„œ ํด๋” ๊ตฌ์กฐ, ์„ค๊ณ„์— ๋Œ€ํ•œ ์•„ํ‚คํ…์ฒ˜๋ฅผ ๋งŒ๋“œ๋Š” ๊ฒƒ์€ ์ƒ๋‹นํžˆ ์–ด๋ ต๋‹ค. ์ด๋ฒˆ ํ”„๋กœ์ ํŠธ์— React FSD ํด๋”๊ตฌ์กฐ ์•„ํ‚คํ…์ฒ˜๋ฅผ ์„ค๊ณ„ํ•  ์˜ˆ์ •์ด๋ผ์„œ FSD ์•„ํ‚คํ…

cometruedream.tistory.com

 

 

https://cometruedream.tistory.com/244

 

์‰ฝ๊ฒŒ ์ดํ•ดํ•˜๊ณ  ์‚ฌ์šฉํ• ์ˆ˜ ์žˆ๋Š” Prisma ๋ช…๋ น์–ด ์ •๋ฆฌ

๐Ÿคท‍โ™‚๏ธ Prisma ๋ช…๋ น์–ด ๋ณธ๋ก ์— ์•ž์„œ Prisma๋ž€?Nest JS ํ”„๋ ˆ์ž„์›Œํฌ์™€ Prisma ORM์„ ํ™œ์šฉํ•ด์„œ ํ”„๋กœ์ ํŠธ๋ฅผ ์ง„ํ–‰ํ•˜๋ฉด์„œ Prisma๋Š” Node JS ๊ธฐ๋ฐ˜์— ํ”„๋ ˆ์ž„์›Œํฌ/๋ผ์ด๋ธŒ๋Ÿฌ๋ฆฌ์™€ ์ƒํ˜ธ์ž‘์šฉ์ด ์ž˜๋˜๋ฉฐ Prisma + DB ์—ฐ๋™์œผ

cometruedream.tistory.com