0.3.0 • Published 3 years ago
@lupa/excel v0.3.0
Installation
Lupa
is on NPM so install using your preferred JS package manager.
yarn add @lupa/excel @lupa/lupa
npm install @lupa/excel @lupa/lupa
Usage
In order for the <ExcelDataset>
component to load, you need to have Office.js loaded. The easiest way to load Office.js is to include the following script tag in your page header
<script src="https://appsforoffice.microsoft.com/lib/1/hosted/Office.js" type="text/javascript"></script>
With Office.js loaded, wrap the top level of your React app in the <ExcelDataset>
component;
import { ExcelDataset } from '@lupa/excel';
export default function App() {
return (
<ExcelDataset>
<div>The rest of my app</div>
<SomeChild />
</ExcelDataset>
)
}
Now in any of the components underneath <ExcelDataset>
you can use the various hooks from @lupa/lupa
;
import React from 'react';
import { useData, useFeatures, useShape } from '@lupa/lupa';
export default function LupaInfo() {
const data = useData();
const features = useFeatures();
const shape = useShape();
const onClick = React.useCallback(async () => {
// We know that `data` is an async function because we're inside <ExcelDataset>
// Generic components should use `dataIsAsyncMethod` or `dataIsRowArray` from '@lupa/lupa'
const d = await data();
console.log(d);
}, [data]);
return (
<div>
<h2>Data</h2>
<div>
<h4>Shape</h4>
{shape}
</div>
<div>
<h4>Features</h4>
{features.map(f => <div key={f.key}>{key}</div>)}
</div>
<div>
<h4>Data</h4>
<button onClick={onClick}>Show data</button>
</div>
</div>
)
}