# Using useEvaluation as a feature flag in React, how do I handle failures safely?

Asked by Victor Mbeki on 2025-03-05. Tags: react, feature-flags, cql.

I'm gating a new checkout flow behind `useEvaluation` in a React SPA. Two questions
before this goes live:

1. What should the component render while the query is still resolving?
2. If the evaluation call fails at runtime (network, whatever), what does the hook
   do? I need a guarantee that users land on the stable checkout, never a broken
   in-between state.

The query itself is simple, something like `user is returning`. Just want the
failure modes nailed down first

## 1 answer

### Accepted answer from Amara Osei (2025-03-05)

The pattern you want is "failure means false", and the SDK is designed to make
that easy.

For the imperative API the documented approach is:

```js
croct.evaluate('user is returning').catch(() => false);
```

Mirror the same idea with the hook: pass an `initial` value of `false` so the
component renders the stable path immediately instead of suspending, and treat
any error state as `false` too. Your users only ever see the new checkout once
the evaluation has positively resolved to true.

Two things that help here:

1. Undefined variables in CQL evaluate to false by design. So if you later gate
   on a custom attribute that has not been set for a user yet, the flag simply
   stays off. No error, no crash.
2. Because the flag defaults to the stable path, a failed evaluation is
   indistinguishable from "not in the audience", which is exactly the degraded
   behavior you want for a checkout.

One caveat: do not cache the result across sessions yourself. Audiences are
evaluated in real time, so `user is returning` can flip mid-session as the
profile updates.

#### Reply from Victor Mbeki (2025-03-06)

The "undefined evaluates to false" detail is exactly the guarantee I needed.
Shipped it with `initial: false` and the rollout has been clean. Thanks.
