You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The way the code is written here (two if statements) suggests that the columns function prop can technically return undefined, allowing a user to fall back to the default internal calculations in the if statement on L82:
// allow user to calculate columns from containerWidth
if(typeofcolumns==='function'){
columns=columns(containerWidth);
}
// set default breakpoints if user doesn't specify columns prop
if(columns===undefined){
columns=1;
if(containerWidth>=500)columns=2;
if(containerWidth>=900)columns=3;
if(containerWidth>=1500)columns=4;
}
I was able to verify this locally. However, the return type for this function is strictly number, so I get type errors if I try to return undefined from the function:
I think it would be nice to update the prop types to allow returning undefined since it seems to work as expected: I can either specify custom logic or return undefined to signal that I want to fall back to the default calculations.
Alternatively, the function could accept a second argument—the default number of columns for containerWidth—so you could do something like this:
The way the code is written here (two
if
statements) suggests that thecolumns
function prop can technically returnundefined
, allowing a user to fall back to the default internal calculations in theif
statement on L82:react-photo-gallery/src/Gallery.js
Lines 76 to 87 in 0bb8e4c
I was able to verify this locally. However, the return type for this function is strictly
number
, so I get type errors if I try to returnundefined
from the function:react-photo-gallery/src/Gallery.js
Line 120 in 0bb8e4c
I think it would be nice to update the prop types to allow returning
undefined
since it seems to work as expected: I can either specify custom logic or returnundefined
to signal that I want to fall back to the default calculations.Alternatively, the function could accept a second argument—the default number of columns for
containerWidth
—so you could do something like this:Happy to put in a PR for this if you approve.
The text was updated successfully, but these errors were encountered: