---
title: "recompileWhen"
description: "Rebuild when your own test of the old and new value says so, for a threshold `crosses` cannot express."
group: "define"
groupTitle: "Defining a shader"
categoryId: "slots"
categorySlug: "slots"
categoryTitle: "Identity & recompile rules"
kind: "function"
sourceUrl: "https://github.com/shader-effects-inc/shaders/blob/main/packages/core/src/std/slots.ts#L46"
---

# recompileWhen

Rebuild when your own test of the old and new value says so, for a threshold `crosses` cannot express.

```ts
recompileWhen(predicate: (prev: any, next: any) => boolean): RecompileRule
```

Import `recompileWhen` from `shaders/std`.

## Parameters

| Name | Type | Notes |
|---|---|---|
| `predicate` | `(prev: any, next: any) => boolean` |  |

## Example

```ts
blur: {default: 0, recompile: recompileWhen((prev, next) => (prev > 0) !== (next > 0))}
```

## See also

- [`crosses`](/docs/primitives/slots/crosses) — Rebuild the shader only when the prop crosses `value`, not on every change.

## Used by

[FlutedGlass](/docs/components/flutedglass), [Glass](/docs/components/glass), [GridDistortion](/docs/components/griddistortion), [ParticleFlow](/docs/components/particleflow), [Surface3D](/docs/components/surface3d)