Hooks API

The custom hooks provided by this package are designed to be used inside the items.

import { <hookName> } from "muuri-react";

useData( [data], [options] ) ๐Ÿ”Œ

Parameters

  • data ย โ€”ย  object
    • The data of the Item in which the hook is called.
    • Optional.
  • options.merge ย โ€”ย  boolean
    • Should new data be merged with old ones or replace them?
    • Default value: false.
    • Optional.

Returns ย โ€”ย  setData( data, [options] )

setData( data, [options] )

Function returned by the hook. The identity of the function is guaranteed to be stable so it will be safe to omit them as a dependency (e.g. if it was used inside a useEffect hook).

Parameters

  • data ย โ€”ย  object
    • The data of the Item in which the hook is called.
  • options.merge ย โ€”ย  boolean
    • Should new data be merged with old ones or replace them?
    • Default value: false.
    • Optional.

Default options

Default options used by setData, useData.

useData.defaultOptions = {merge: false};

useDrag( ) ๐Ÿ”Œ

The Item will re-render on each drag start/end.

Returns ย โ€”ย  boolean

useDraggable( ) ๐Ÿ”Œ

Return the drag enabler method.

Returns ย โ€”ย  setDraggable( )

setDraggable( draggable )

Function returned by the hook. The identity of the function is guaranteed to be stable so it will be safe to omit them as a dependency (e.g. if it was used inside a useEffect hook).

Parameters

  • draggable ย โ€”ย  boolean
    • A truthy value to allow the Item to be dragged, a falsy value to not allow the Item to be dragged.

useGrid( ) ๐Ÿ”Œ

Returns ย โ€”ย  GridData

  • GridData.id ย โ€”ย  string
    • The id of the MuuriComponent of which the Item is a child.
  • GridData.groupIds ย โ€”ย  array
    • The group ids of the MuuriComponent of which the Item is a child.
  • GridData.grid ย โ€”ย  Muuri
    • The Muuri instance of the MuuriComponent of which the Item is a child.

useRefresh( [deps] ) ๐Ÿ”Œ

Show the targeted Items.

Parameters

  • deps ย โ€”ย  array
    • An array of dependencies, it has the same purpose as in useEffect.
    • Default value: [].
    • Optional.

Returns ย โ€”ย  refresh( )

refresh( )

Function returned by the hook. The identity of the function is guaranteed to be stable so it will be safe to omit them as a dependency (e.g. if it was used inside a useEffect hook).

useShow( ) ๐Ÿ”Œ

The Item will re-render each time its visibility change.

Returns ย โ€”ย  boolean

useVisibility( ) ๐Ÿ”Œ

Return the visibility setter method.

Returns ย โ€”ย  setVisibility( )

setVisibility( visibility, [options] )

Function returned by the hook. The identity of the function is guaranteed to be stable so it will be safe to omit them as a dependency (e.g. if it was used inside a useEffect hook).

Parameters

  • visibility ย โ€”ย  boolean

    • A truthy value to show the Item, a falsy value to hide the Item.
  • options.instant ย โ€”ย  boolean

    • Should the animation happen instantly?
    • Default value: false.
    • Optional.

Default options

Default options used by setVisibility.

useData.defaultOptions = {instant: false};