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

window is not defined for Table Columns #2287

Closed
MelikeBicerr opened this issue Jan 6, 2022 · 4 comments · Fixed by rsuite/rsuite-table#294
Closed

window is not defined for Table Columns #2287

MelikeBicerr opened this issue Jan 6, 2022 · 4 comments · Fixed by rsuite/rsuite-table#294

Comments

@MelikeBicerr
Copy link

What version of rsuite are you using?

5.4.4

What version of React are you using?

17.0.2

What version of TypeScript are you using (if any)?

No response

What browser are you using?

Brave, Firefox

Describe the Bug

Getting window is not defined error for Table Columns on new project. If I comment out Columns then it works.

Error

ReferenceError: window is not defined
Uncaught at isSupportTouchEvent

Sample Code

import { Table } from "rsuite";
import { useEffect } from "react";

const { Column, HeaderCell, Cell } = Table;

const CustomTable = (props) => {
  useEffect(() => {
    console.log("RTABLE");
  });
  return (
    <Table
      height={400}
      data={props.data}
    >
      <Column width={100} align="center" key={props.data.label}>
        <HeaderCell>{props.label}</HeaderCell>
        <Cell dataKey="label" />
      </Column>
    </Table>
  );
};

export default CustomTable;

props.data is valid and loaded after a loading component. Normally we are using rsuite and it's table component on several projects without an issue but this time it throws the error above and couldn't figure it out on why?

Expected Behavior

Rendering Table component without an issue

To Reproduce

https://codesandbox.io/s/thirsty-sun-pqs69?file=/src/index.js

this is working on codesandbox but not on my end

@SevenOutman
Copy link
Member

Hi @MelikeBicerr, are you doing server-side rendering or using some frameworks like Next.js?

@fuzunspm
Copy link

fuzunspm commented Jan 6, 2022

I reproduced the problem on next.js and able to fix it by wrapping Table like this:

return (
...
{typeof window !== "undefined" ? (<Table ....) : null}
...
)

is this necessary or I'm missing a key point here?

@SevenOutman
Copy link
Member

@simonguo
Copy link
Member

I will fix it in this week's new version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants