Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Lars-Janssen's avatar

Inertia react preserveState not working

I'm trying to reload my page but keep the filters state with Inertia.

Like this:

const [allProducts, setAllProducts] = useState([]);
    
const [filters, setFilters] = useState([]);

const fetchProducts = (page) => {
    Inertia.get(
      `/products?page=${page}`,
      { filters },
      {
        preserveState: true,
        preserveScroll: true,
        only: ['products'],
        onSuccess: (response) => {
          setAllProducts(allProducts.concat(response.props.products.data));
          page += 1;
        }
      }
    )
});

The problem is that filters and allProducts are reset even though preserveState = true.

0 likes
0 replies

Please or to participate in this conversation.