Function patternfly_yew::hooks::pagination::use_pagination

source ·
pub fn use_pagination<'hook, T>(
    total: Option<usize>,
    init: T
) -> impl 'hook + Hook<Output = UsePagination>
where T: FnOnce() -> PaginationControl + 'hook,
Expand description

Create a hook for managing pagination state.

If known, the hook takes in a total number of items to be shown, otherwise it will be an unbounded pagination control. The state will be initialized using the initializer function.

The hook returns a struct to manage and track pagination state. It is intended to be used in combination with the crate::components::pagination::SimplePagination component.

§Example

Also see the quickstart project for a full example.

use yew::prelude::*;
use patternfly_yew::prelude::*;

#[function_component(Example)]
fn example() -> Html {
  let total = use_state_eq(||Some(123));
  let pagination = use_pagination(*total, Default::default);

  html!(
    <>
      <SimplePagination
        pagination={pagination.clone()}
        total={*total}
      />
      // ... render content
      { format!("Showing items: {:?}", pagination.state.range()) }
      <SimplePagination
        pagination={pagination.clone()}
        total={*total}
        position={PaginationPosition::Bottom}
      />
    </>
  )
}

§Note

When used in function components and hooks, this hook is equivalent to:

pub fn use_pagination<T>(total: Option<usize>, init: T) -> UsePagination
where
    T: FnOnce() -> PaginationControl,
{
    /* implementation omitted */
}