Calculate on-demand

Trigger a full recalc whenever you need it.

If you are uploading an excel file or replacing the state of the spreadsheet, you will have to manually trigger a full recalc.

You can also disable formula evaluation or reset teh cell dependency graph using options.

To do so, useSpreadsheetState exposes calculateNow function.

import {
  SpreadsheetProvider,
  CanvasGrid,
} from "@rowsncolumns/spreadsheet";
import { useSpreadsheetState } from "@rowsncolumns/spreadsheet-state";

const MySpreadsheet = () => {
  const { calculateNow } = useSpreadsheetState({
    ...
  });
  return (
    <div>
      <input type="file" onChange={() => {
        // Update sheets
        // update sheet Data
        // Update table
        calculateNow({
          // Formulas are not evaluated, only cell dependency graph is rebuilt
          disableEvaluation: true,
          // Optionally reset the entire dependency graph
          resetDependencyGraph: true,
        })
      })
      <CanvasGrid />
    </div>
  );
};

const App = () => (
  <SpreadsheetProvider>
    <MySpreadsheet />
  </SpreadsheetProvider>
);

Last updated