Skip to content
This repository has been archived by the owner on Apr 4, 2023. It is now read-only.

Commit

Permalink
Fix window is not defined
Browse files Browse the repository at this point in the history
  • Loading branch information
mustofa-id committed Jul 2, 2019
1 parent d4912fc commit 089bbae
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions src/components/widget/masonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,29 @@ const Masonry = ({ column, children, breakpoint }) => {
const [columnCount, setColumnCount] = useState(getColumnCount())

useEffect(() => {
if (window) {
if (typeof window !== 'undefined') {
updateColumn()
window.addEventListener('resize', updateColumn)
return () => window.removeEventListener('resize', updateColumn)
}
})

function getColumnCount () {
const width = (window && window.innerWidth) || Infinity
let matchedBreakpoint = Infinity
let columns = breakpoint.default
for (let bp in breakpoint) {
const optBreakpoint = parseInt(bp)
const isCurrentBreakpoint = optBreakpoint > 0 && width <= optBreakpoint
if (isCurrentBreakpoint && optBreakpoint < matchedBreakpoint) {
matchedBreakpoint = optBreakpoint
columns = breakpoint[bp]
if (typeof window !== 'undefined') {
const width = (window.innerWidth) || Infinity
let matchedBreakpoint = Infinity
let columns = breakpoint.default
for (let bp in breakpoint) {
const optBreakpoint = parseInt(bp)
const isCurrentBreakpoint = optBreakpoint > 0 && width <= optBreakpoint
if (isCurrentBreakpoint && optBreakpoint < matchedBreakpoint) {
matchedBreakpoint = optBreakpoint
columns = breakpoint[bp]
}
}
return Math.max(1, parseInt(columns) || 1)
}
return Math.max(1, parseInt(columns) || 1)
return 0
}

function updateColumn () {
Expand Down

0 comments on commit 089bbae

Please sign in to comment.