1.0.3 • Published 6 months ago

@vtaits/react-filterlist-router-5 v1.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
6 months ago

NPM dependencies status

@vtaits/react-filterlist-router-5

Integration of @vtaits/filterlist with react-router-dom v5

Installation

npm install @vtaits/filterlist @vtaits/react-filterlist @vtaits/react-filterlist-router-5 --save

or

yarn add @vtaits/filterlist @vtaits/react-filterlist @vtaits/react-filterlist-router-5

Simple examples

import { useFilterlist } from '@vtaits/react-filterlist';
import { useCreateDataStore } from '@vtaits/react-filterlist-router-5';

function List() {
  const createDataStore = useCreateDataStore();

  const [requestParams, listState, filterlist] = useFilterlist({
    createDataStore,

    loadItems: async () => {
      const response = await fetch('/cars');
      const cars = await response.json();

      return {
        items: cars,
				total: cars.length,
      };
    },
  });

  const {
    items,
    loading,
    total,
  } = listState;

  return (
    <div>
      <table>
        <thead>
          <tr>
            <th>id</th>
            <th>brand</th>
            <th>owner</th>
            <th>color</th>
          </tr>
        </thead>

        <tbody>
          {
            items.map(({
              id,
              brand,
              owner,
              color,
            }) => (
              <tr key={ id }>
                <td>{ id }</td>
                <td>{ brand }</td>
                <td>{ owner }</td>
                <td>{ color }</td>
              </tr>
            ))
          }
        </tbody>
      </table>

      {
        typeof total === 'number' && (
          <h4>
            Total: {total}
          </h4>
        )
      }

      {
        loading && (
          <h3>Loading...</h3>
        )
      }
    </div>
  );
};
1.0.3-signals.0

6 months ago

1.0.3

6 months ago

1.0.2-signals.0

8 months ago

1.0.2

11 months ago

1.0.1

11 months ago

1.0.0

11 months ago