Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maximum update depth exceeded: React warning occasionally #279

Open
rrrepos opened this issue Feb 12, 2023 · 4 comments
Open

Maximum update depth exceeded: React warning occasionally #279

rrrepos opened this issue Feb 12, 2023 · 4 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@rrrepos
Copy link

rrrepos commented Feb 12, 2023

The console occasionally shows the following warning indicating some sort of infinite rendering. The error message is:

Maximum update depth exceeded. This can happen when a component calls setState inside useEffect, but useEffect either doesn't have a dependency array, or one of the dependencies changes on every render.

I am using this wonderful component in the following manner. Key code has been shown

// component
import ...

const Component = (props) => {

  useEffect(() => {
    const populateSheet = () => {
         // logic to read props data and put it into array
        // required by SS
       return data
    }
    setData(populateSheet())
  }, [])

  return (
     <Spreadsheet
            hideColumnIndicators={true}
            hideRowIndicators={true}
            data={data}
            onChange={setData} />
   )   
}

I find that the error shows up when I blank out a cell in the spreadsheet. Not everytime but occasionally. Thanks

@rrrepos
Copy link
Author

rrrepos commented Feb 12, 2023

The warning shows up when I place the cursor in a cell and use the Backspace key on Chrome browser (v 107.0.xxx) in Desktop

@iddan iddan added bug Something isn't working good first issue Good for newcomers labels Feb 19, 2023
@iddan
Copy link
Owner

iddan commented Feb 19, 2023

Thank you for reporting

@coopslarhette
Copy link

also running into this, seems to happen when the value for two cells is the same I think

is value used as a key prop anywhere?

@EdoardoGruppi
Copy link

Hello,

I've just submitted a pull request to address this issue. To fix it on your end before my pull request is accepted and merged into the main project, you can follow these steps:

  1. Clone the branch where I made the modifications:

    git clone -b fix-maximum-update-depth-exceeded https://github.com/EdoardoGruppi/react-spreadsheet.git
    
  2. Install the necessary packages using npm:

    npm install
    

    If the packages "@typescript-eslint/eslint-plugin" and "@typescript-eslint/parser" cause any issues, simply remove them from the package.json file and run npm install again.

  3. Build the project to generate the dist folder:

    npm run build
    
  4. Replace the existing dist folder inside node_modules/react-spreadsheet with the newly created one.

If there's any caching involved, make sure to clear it before running your code again. For example, if you're using Vite, delete the .vite folder inside node_modules.

For more details on the changes made, you can refer to my pull request here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

4 participants