1.0.8 • Published 10 months ago

@hizzlewp/store v1.0.8

Weekly downloads
-
License
GPL-2.0-or-later
Repository
github
Last release
10 months ago

State management package.

Installation

npm install @hizzlewp/store

Usage

import { initStore, useRecords } from '@hizzlewp/store';

// Init a store for a specific namespace and collection.
// Do this once in your app.
initStore( 'noptin', 'subscribers' );

// In your component, use the useRecords hook to get the records.
export ListRecords = ( {per_page} ) => {
    const { data, total, summary, isResolving, hasResolutionFailed, getResolutionError } = useRecords( 'noptin', 'subscribers', { per_page } );

    // Check if the records are still loading.
    if ( isResolving() ) {
        return <div>Loading...</div>;
    }

    // Check if the records failed to load.
    if ( hasResolutionFailed() ) {
        return <div>Error: { getResolutionError() }</div>;
    }

    // Render the records.
    return (
        <div>
            <ul>
                { data.map( ( record ) => <li key={ record.id }>{ record.email }</li> ) }
            </ul>
            <p>Total: { total }</p>
            <p>Summary: { summary }</p>
        </div>
    );
}
1.0.2

11 months ago

1.0.1

12 months ago

1.0.8

10 months ago

1.0.7

11 months ago

1.0.6

11 months ago

1.0.5

11 months ago

1.0.4

11 months ago

1.0.3

11 months ago

0.0.3

3 years ago

0.0.2

3 years ago