function usePositioner(
  {width, columnWidth = 200, columnGutter = 0, rowGutter, columnCount},
  deps = emptyArr
) {
  const initPositioner = () => {
    const [computedColumnWidth, computedColumnCount] = getColumns(
      width,
      columnWidth,
      columnGutter,
      columnCount
    )
    return createPositioner(
      computedColumnCount,
      computedColumnWidth,
      columnGutter,
      rowGutter !== null && rowGutter !== void 0 ? rowGutter : columnGutter
    )
  }

  const positionerRef = React.useRef()
  if (positionerRef.current === undefined)
    positionerRef.current = initPositioner()
  const prevDeps = React.useRef(deps)
  const opts = [width, columnWidth, columnGutter, rowGutter, columnCount]
  const prevOpts = React.useRef(opts)
  const optsChanged = !opts.every((item, i) => prevOpts.current[i] === item)

  if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
    if (deps.length !== prevDeps.current.length) {
      throw new Error(
        'usePositioner(): The length of your dependencies array changed.'
      )
    }
  } // Create a new positioner when the dependencies or sizes change
  // Thanks to https://github.com/khmm12 for pointing this out
  // https://github.com/jaredLunde/masonic/pull/41

  if (optsChanged || !deps.every((item, i) => prevDeps.current[i] === item)) {
    const prevPositioner = positionerRef.current
    const positioner = initPositioner()
    prevDeps.current = deps
    prevOpts.current = opts

    if (optsChanged) {
      const cacheSize = prevPositioner.size()

      for (let index = 0; index < cacheSize; index++) {
        const pos = prevPositioner.get(index)
        positioner.set(index, pos !== void 0 ? pos.height : 0)
      }
    }

    positionerRef.current = positioner
  }

  return positionerRef.current
}
/**
 * This hook creates the grid cell positioner and cache required by `useMasonry()`. This is
 * the meat of the grid's layout algorithm, determining which cells to render at a given scroll
 * position, as well as where to place new items in the grid.
 *
 * @param options Properties that determine the number of columns in the grid, as well
 *  as their widths.
 * @param deps This hook will create a new positioner, clearing all existing cached positions,
 *  whenever the dependencies in this list change.
 */
This hook creates the grid cell positioner and cache required by `useMasonry()`. This is
the meat of the grid's layout algorithm, determining which cells to render at a given scroll
position, as well as where to place new items in the grid.

@param options Properties that determine the number of columns in the grid, as well
as their widths.
@param deps This hook will create a new positioner, clearing all existing cached positions,
whenever the dependencies in this list change.
This hook creates the grid cell positioner and cache required by ` useMasonry () ` . This is the meat of the grid ' s layout algorithm determining which cells to render at a given scroll position as well as where to place new items in the grid . @param options Properties that determine the number of columns in the grid as well as their widths . @param deps This hook will create a new positioner clearing all existing cached positions whenever the dependencies in this list change .
function usePositioner(
  {width, columnWidth = 200, columnGutter = 0, rowGutter, columnCount},
  deps = emptyArr
) {
  const initPositioner = () => {
    const [computedColumnWidth, computedColumnCount] = getColumns(
      width,
      columnWidth,
      columnGutter,
      columnCount
    )
    return createPositioner(
      computedColumnCount,
      computedColumnWidth,
      columnGutter,
      rowGutter !== null && rowGutter !== void 0 ? rowGutter : columnGutter
    )
  }
  const positionerRef = React.useRef()
  if (positionerRef.current === undefined)
    positionerRef.current = initPositioner()
  const prevDeps = React.useRef(deps)
  const opts = [width, columnWidth, columnGutter, rowGutter, columnCount]
  const prevOpts = React.useRef(opts)
  const optsChanged = !opts.every((item, i) => prevOpts.current[i] === item)
  if (typeof process !== 'undefined' && process.env.NODE_ENV !== 'production') {
    if (deps.length !== prevDeps.current.length) {
      throw new Error(
        'usePositioner(): The length of your dependencies array changed.'
      )
    }
  } 
  if (optsChanged || !deps.every((item, i) => prevDeps.current[i] === item)) {
    const prevPositioner = positionerRef.current
    const positioner = initPositioner()
    prevDeps.current = deps
    prevOpts.current = opts
    if (optsChanged) {
      const cacheSize = prevPositioner.size()
      for (let index = 0; index < cacheSize; index++) {
        const pos = prevPositioner.get(index)
        positioner.set(index, pos !== void 0 ? pos.height : 0)
      }
    }
    positionerRef.current = positioner
  }
  return positionerRef.current
}
function usePositioner ( { width , columnWidth = 200 , columnGutter = 0 , rowGutter , columnCount } , deps = emptyArr ) { const initPositioner = ( ) => { const [ computedColumnWidth , computedColumnCount ] = getColumns ( width , columnWidth , columnGutter , columnCount ) return createPositioner ( computedColumnCount , computedColumnWidth , columnGutter , rowGutter !== null && rowGutter !== void 0 ? rowGutter : columnGutter ) } const positionerRef = React . useRef ( ) if ( positionerRef . current === undefined ) positionerRef . current = initPositioner ( ) const prevDeps = React . useRef ( deps ) const opts = [ width , columnWidth , columnGutter , rowGutter , columnCount ] const prevOpts = React . useRef ( opts ) const optsChanged = ! opts . every ( ( item , i ) => prevOpts . current [ i ] === item ) if ( typeof process !== 'undefined' && process . env . NODE_ENV !== 'production' ) { if ( deps . length !== prevDeps . current . length ) { throw new Error ( 'usePositioner(): The length of your dependencies array changed.' ) } } if ( optsChanged || ! deps . every ( ( item , i ) => prevDeps . current [ i ] === item ) ) { const prevPositioner = positionerRef . current const positioner = initPositioner ( ) prevDeps . current = deps prevOpts . current = opts if ( optsChanged ) { const cacheSize = prevPositioner . size ( ) for ( let index = 0 ; index < cacheSize ; index ++ ) { const pos = prevPositioner . get ( index ) positioner . set ( index , pos !== void 0 ? pos . height : 0 ) } } positionerRef . current = positioner } return positionerRef . current }
This hook creates the grid cell positioner and cache required by `useMasonry()`.
This hook creates the grid cell positioner and cache required by ` useMasonry () ` .
// Create a new positioner when the dependencies or sizes change // Thanks to https://github.com/khmm12 for pointing this out // https://github.com/jaredLunde/masonic/pull/41