Skip to content

React: Get all data from Table from a onclick function

I have react app with a react-spreadsheet component and a button. I am trying to get the data from the spreadsheet on the onclick() event of the button.

import * as React from 'react';
import PropTypes from 'prop-types';
import Tabs from '@mui/material/Tabs';
import Tab from '@mui/material/Tab';
import Typography from '@mui/material/Typography';
import Box from '@mui/material/Box';
import { TextField, Button } from '@mui/material';
import './App.css';

import Spreadsheet from "react-spreadsheet";

import Dropdown from 'react-dropdown';
import 'react-dropdown/style.css';

function TabPanel(props) {
  const { children, value, index, ...other } = props;

  return (
      hidden={value !== index}
      {value === index && (
        <Box sx={{ p: 3 }}>

function loadBatchInput() {

function App() {
  const [tabValue, setValue] = React.useState(0);

  const handleChange = (event, newValue) => {

  //batch input excel
  const [batchInputData, setbatchInputData] = React.useState([
    [{ value: "Type"}, { value: "Region" }, { value: "Product" }, { value: "Brand" }, { value: "Sku_Type" }],

  return (
    <div className="App">
      <div className="content">
          <TabPanel value={tabValue} index={0}>
            <div className='rowA'>
                Batch Input Table
                <Button variant="contained" onClick={() => loadBatchInput() }>Load Batch Input</Button>
                <Spreadsheet data={batchInputData} onChange={setbatchInputData} />

export default App;

I am trying to get the data added to the spreadsheet via the webpage inside a JavaScript function.

Is there a way to get the react-spreadsheet data(if any added via frontend) inside the loadBatchInput() on click of the Load Batch Input button




In your loadBatchInput() function, you will need to add your data to the 2nd element of the array of your batchInputData state. You can do so with the following:

  const loadBatchInput = () => {
    let batch = [...batchInputData];
    batch[1] = [{value: 'data'}]
User contributions licensed under: CC BY-SA
8 People found this is helpful