-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Getting Maximun call stack In production. #1739
Comments
Are you using the latest release candidate version? |
@tannerlinsley i'm using "react-table": "^7.0.0-rc.6" this version. |
Comment out the effect. Does it still happen? |
After commenting the effect works it's fine. |
That is strange. useEffect should not be running in an SSR environment. What are you building your app in? Next? |
I'm using Reactjs |
Yes, but how and when are you doing server side rendering? |
No, we are not doing the SSR. Running the app using the express server. |
So you are rendering the app html Using express, then using React normally on the client? |
I’ve updated the issue to better reflect the question you’re asking. |
What’s happening is that your effect is using a dependency that is likely changing from the effect itself. Thus you get an infinite call stack. |
I think the best thing to do here is to make a codesandbox that illustrates the issue. It will be 100x easier for me to debug from there. |
Please comment with a codesandbox demonstrating the issue and we can reopen this issue :) |
I'm facing a similar issue, I also have a similar code than him. Something i could add is the _setSelected (named setSelectedRows) function passed in params to his Table component, is setting the state in the parent component. So it causes a rerendering of the Table component which changes selectedFlatRows (maybe ?) so the useEffect is called again so the infinite loop starts again and again. To solve this issue, i remove the It worked for me because i didn't really need that selectedRows in the parent component state, but what if i really needed it ? How can i solve this ? 'Cause i think i'm gonna soon need it. EDIT : i'm using |
I've found workaround for this issue, insipred by this conversation First you have to set initialState.selectedRowIds but make sure it's never recreated during render: const INITIAL_SELECTED_ROW_IDS = {};
const DataTable = ({ data, columns, onSelectedRowChange }) => {
const {
getTableProps,
page,
prepareRow,
headerGroups,
pageCount,
gotoPage,
state: { pageIndex, selectedRowIds }, // selectedRowPaths is renamed to selectedRowIds
} = useTable(
{
data,
columns,
initialState: {
pageSize: pageSize,
selectedRowIds: INITIAL_SELECTED_ROW_IDS // Do not just use {}
}
},
... and re-implement selectedFlatRows's behavior like this: import { useMountedLayoutEffect } from "react-table";
...
useMountedLayoutEffect(() => {
const selectedIds = Object.keys(selectedRowIds);
var selectedRowsData = selectedIds
.map(x => data[x])
.filter(function(x) {
return x != null;
});
onSelectedRowChange(selectedRowsData);
}, [onSelectedRowChange, selectedRowIds]); |
@iAmGhost : is it mandatory to give initialState for selectedRowIds , beacuse UI will load with pre-selected rows , is there any other way ? |
I am running into this issue as well. It runs regardless of whether or not a selection was made. |
I hit this same thread and eliminated the infinite rendering by adding
|
It is very strange behavior and it is hint when using react-table select rows feature. const tableInstance = useTable({
columns,
data,
autoResetHiddenColumns: false, // <-- stops the rerendering 🥳
autoResetSortBy: false, // <-- stops the rerendering 🥳
}, useSortBy); |
None of the above (or anywhere else on the interwebs) worked for me but here's what did. And I imagine, with the number of people who've asked this same question about React Table v7, that in version 8 of React Table, the state, especially state having to do with selection, has been ironed out. But anyway this is the ONLY workaround that worked for me, loosely based on this codesandbox. // Parent component
// And the Table / child
|
I'm getting maximum call stack in production but during dev, it's working fine. Follow is the code I'm using.
The text was updated successfully, but these errors were encountered: