<p>Since you call <code>.all()</code> on the element queries, <code>entries</code> represents an array and therefore you cannot call <code>.offset()</code> on it. Leaving out <code>.all()</code> would allow you to call other functions on the query, for example:</p>
<pre><code>{% set entryQuery = craft.entries.section(block.blockItemsAuto) %}

{% set entries = entryQuery.offset(offset).limit(limit).all() %}
</code></pre>
<p>However, when using Sprig you should never pass objects (or arrays of objects) into a component, see <a href="https://putyourlightson.com/plugins/sprig#component-variables" rel="nofollow noreferrer">https://putyourlightson.com/plugins/sprig#component-variables</a> :</p>
<blockquote>
<p>Only primitive data types can be used as values: strings, numbers, booleans and arrays. Objects, models and elements cannot be used. If you want to pass an element (or set of elements) into a Sprig component then you should pass in an ID (or array of IDs) instead and then fetch the element from within the component.</p>
</blockquote>
<p>So in this case I think you'd be better off either moving all of the logic into the component, or just passing an array of entry IDs into it.</p>

CC BY-SA 4.0
2023-03-07T04:59:39.020Z
I've used the array of entry IDs with success in a few instances. Can confirm it works great.
cherrykoda
CC BY-SA 4.0
2023-02-19T14:39:59.463Z
2023-02-19T14:39:59.463Z
Ben Croker
<p>I'm trying to create a load more function using a filtered set of entries, then passing those entries into the Load More component using Sprig.</p>
<p>I get the error &quot;Impossible to invoke a method (&quot;offset&quot;) on an array.&quot;</p>
<p>This is the code</p>
<p><strong>Template</strong></p>
<pre><code>    {# If the user has selected &quot;Auto&quot; it'll auto populate below from section selected. #}
    {% if block.blockItemsManual|length %}
        {% set entries = block.blockItemsManual.entries.all() %}
    {% else %}
        {% set entries = craft.entries.section(block.blockItemsAuto).all() %}
    {% endif %}
    {# Show a Load More button that loads in more data via Sprig #}
    {{ sprig('_components/loadMore_grid', {'limit': 3, 'selectedEntries': entries }) }}
    {{ sprig.script }}
</code></pre>
<p><strong>Component</strong></p>
<pre><code>{# Sets a default value if not defined by the `s-val:*` attribute on the button #}
{% set offset = offset ?? 0 %}

{% set entryQuery = selectedEntries.offset(offset).limit(limit) %}
{% set entries = entryQuery.all() %}


{% for entry in entries %}
......
</code></pre>

<craft4><plugin-sprig>
Offset on an array (Sprig)
# Offset on an array (Sprig)

(Asked by: username_0 on 2023-02-18)

I'm trying to create a load more function using a filtered set of entries, then passing those entries into the Load More component using Sprig.
I get the error "Impossible to invoke a method ("offset") on an array."
This is the code
Template
    {# If the user has selected "Auto" it'll auto populate below from section selected. #}
    {% if block.blockItemsManual|length %}
        {% set entries = block.blockItemsManual.entries.all() %}
    {% else %}
        {% set entries = craft.entries.section(block.blockItemsAuto).all() %}
    {% endif %}
    {# Show a Load More button that loads in more data via Sprig #}
    {{ sprig('_components/loadMore_grid', {'limit': 3, 'selectedEntries': entries }) }}
    {{ sprig.script }}

Component
{# Sets a default value if not defined by the `s-val:*` attribute on the button #}
{% set offset = offset ?? 0 %}

{% set entryQuery = selectedEntries.offset(offset).limit(limit) %}
{% set entries = entryQuery.all() %}


{% for entry in entries %}
......

**Tags:** craft4, plugin-sprig

---

## 1 answers

### Answer by username_1 on 2023-02-19. Score: 2

Since you call .all() on the element queries, entries represents an array and therefore you cannot call .offset() on it. Leaving out .all() would allow you to call other functions on the query, for example:
{% set entryQuery = craft.entries.section(block.blockItemsAuto) %}

{% set entries = entryQuery.offset(offset).limit(limit).all() %}

However, when using Sprig you should never pass objects (or arrays of objects) into a component, see https://putyourlightson.com/plugins/sprig#component-variables :

Only primitive data types can be used as values: strings, numbers, booleans and arrays. Objects, models and elements cannot be used. If you want to pass an element (or set of elements) into a Sprig component then you should pass in an ID (or array of IDs) instead and then fetch the element from within the component.

So in this case I think you'd be better off either moving all of the logic into the component, or just passing an array of entry IDs into it.

> **Comments:**
> **username_2**: I've used the array of entry IDs with success in a few instances. Can confirm it works great.  

---

