Shadcn Sidebar Error during linting
Unanswered
Cuvier’s Dwarf Caiman posted this in #help-forum
Cuvier’s Dwarf CaimanOP
Do you guys know how to fix this?
8 Replies
Cuvier’s Dwarf CaimanOP
Error: Cannot call impure function during render
Math.random is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent).
C:\Users\ACER\Desktop\next-capture\components\ui\sidebar.tsx:611:26
609 | }) {
610 | const width = useMemo(() => {
| ^^^^^^^^^^^^^ Cannot call impure function
612 | }, []);
Math.random is an impure function. Calling an impure function can produce unstable results that update unpredictably when the component happens to re-render. (https://react.dev/reference/rules/components-and-hooks-must-be-pure#components-and-hooks-must-be-idempotent).
C:\Users\ACER\Desktop\next-capture\components\ui\sidebar.tsx:611:26
609 | }) {
610 | const width = useMemo(() => {
611 | return ${Math.floor(Math.random() * 40) + 50}%;
| ^^^^^^^^^^^^^ Cannot call impure function
612 | }, []);
@Cuvier’s Dwarf Caiman Do you guys know how to fix this?
just for me: why would you would want to have a random width for a sidebar?
@B33fb0n3 just for me: why would you would want to have a random width for a sidebar?
Cuvier’s Dwarf CaimanOP
I just install the sidebar component from Shadcn library bro im not the one implementing that
@Cuvier’s Dwarf Caiman I just install the sidebar component from Shadcn library bro im not the one implementing that
you are right lol. It does not throw an error for me. So you have two options rn:
1. change your linter settings
2. write it as the following:
It should still generate a random width for each
1. change your linter settings
2. write it as the following:
const width = `${Math.floor(Math.random() * 40) + 50}%`It should still generate a random width for each
SidebarMenuSkeleton that exists@B33fb0n3 you are right lol. It does not throw an error for me. So you have two options rn:
1. change your linter settings
2. write it as the following:
tsx
const width = `${Math.floor(Math.random() * 40) + 50}%`
It should still generate a random width for each `SidebarMenuSkeleton` that exists
Cuvier’s Dwarf CaimanOP
What lintter do you use? I use builtin eslint for nextjs
I am using [biome](https://biomejs.dev/). It needs a bit of configuration, so it works right. If you want to switch, this is my default config for biome:
biome.json@Cuvier’s Dwarf Caimansolved?
Cuvier’s Dwarf CaimanOP
Yup it worked! Thank you