Usage with Astro

How to use the library with Astro

Create a new Astro project

  1. Run the following command:
bash
npm create astro@latest
  1. Select the default options:
bash
 astro   Launch sequence initiated.
 
   dir   Where should we create your new project?
         ./astro-project
 
  tmpl   How would you like to start your new project?
         Include sample files
 
    ts   Do you plan to write TypeScript?
         Yes
 
   use   How strict should TypeScript be?
         Strict
 
  deps   Install dependencies?
         Yes
 
   git   Initialize a new git repository?
         Yes
 
  Project initialized!
 Template copied
 TypeScript customized
 Dependencies installed
 Git initialized
  1. Add @astrojs/react integration:
bash
npx astro add react

Add the library

  1. Run the following command:
bash
  1. Add the JsonViewer to the page file:

💡 Add client:load directive to the JsonViewer component.

js
// 📄 pages/index.astro
 
---
 
import { JsonViewer } from '@franmella/json-viewer';
 
---
 
<main>
    <JsonViewer client:load />
</main>
  1. Pass the JSON data to the JsonViewer component:
js
// 📄 pages/index.astro
 
---
 
import { JsonViewer } from '@franmella/json-viewer';
 
const json = {
  name: 'John Doe',
  age: 30,
  email: "test@test.com",
  address: {
    street: '123 Main St',
    city: 'New York',
    state: 'NY',
    zip: '10001'
  }
}
 
---
 
<main>
    <JsonViewer client:load data={json} />
</main>