Function useActions

  • Preact hook that import current actions to the component. Actions should be used to modify state, making new searches, etc.

    Should always be at the top of the component!

    Returns {
        newSearch(query: SearchQuery, options?: SearchOptions): Promise<void>;
        replaceFilter(
            field: string,
            value: undefined | string | InputSearchRangeFilter,
        ): Promise<void>;
        simulateUpdateSearch(
            query: SearchQuery,
            options?: SearchOptions,
        ): { url: URL };
        toggleProductFilter(
            field: string,
            value: string,
            active: boolean,
        ): Promise<void>;
        updateSearch(query: SearchQuery, options?: SearchOptions): Promise<void>;
    }

    import { useActions } from '@nosto/preact'

    export default () => {
    const { newSearch } = useActions()

    return <button onClick={() => {
    newSearch({
    query: {
    query: "samsung"
    }
    })
    }}>
    Search for "samsung"
    </button>
    }