Home > Mobile >  TypeError: Cannot read properties of null (reading 'length') in Nextjs error
TypeError: Cannot read properties of null (reading 'length') in Nextjs error

Time:03-03

I am getting such an error in nextjs files:

  117 |   };
  118 | 
> 119 |   if (data.length <= 0) {
      |           ^
  120 |     return null;
  121 |   }
  122 | 

if I want to show it with a photo, it is as follows:enter image description here

The project works on different computers, but it doesn't work on me. How do I fix this error? enter image description here

i also encounter different errors every time I refresh the page. enter image description here

17354 |     ReactCurrentOwner$1.current = workInProgress;
  17355 |     setIsRendering(true);
> 17356 |     nextChildren = renderWithHooks(current, workInProgress, Component, nextProps, context, renderLanes);
  17357 | 
  17358 |     if ( workInProgress.mode & StrictMode) {
  17359 |       disableLogs();

CodePudding user response:

Use this way

if (data?.length <= 0) {
//any code
}

CodePudding user response:

It's throwing that error because there is no data length to read.

Try this instead:

if (!data.length) {
      return null
}
  • Related