# invalid_argument

> A function, part, or hook received an argument it can't use, such as an amount of 0, a range whose minimum is above its maximum, an unknown system, or unparsed recipe input.

Source: https://recipe-book.siraj.page/errors/invalid_argument/

A function from `@recipe-book/core`, or a part or hook from `@recipe-book/react`, received an argument it can't use. The message names the function, part, or hook, what it expects, and usually the value it received:

```txt
RecipeBookError: convert: amount must be a finite number greater than 0, received NaN.
See https://recipe-book.siraj.page/errors/invalid_argument/
```

Recipe Book checks arguments rather than returning `NaN` or a wrong amount that would surface later in a recipe. The value usually comes from data, such as a form field or a URL, that your code passed in without checking.

The name is one of the core functions [`convert`](https://recipe-book.siraj.page/reference/core/units.md#convert), [`toSystem`](https://recipe-book.siraj.page/reference/core/units.md#tosystem), [`convertTemperature`](https://recipe-book.siraj.page/reference/core/units.md#converttemperature), [`segmentStepText`](https://recipe-book.siraj.page/reference/core/units.md#segmentsteptext), [`segmentStepQuantities`](https://recipe-book.siraj.page/reference/core/units.md#segmentstepquantities), [`scaleQuantity`](https://recipe-book.siraj.page/reference/core/resolving.md#scalequantity), [`resolveIngredient`](https://recipe-book.siraj.page/reference/core/resolving.md#resolveingredient), [`formatQuantity`](https://recipe-book.siraj.page/reference/core/formatting.md#formatquantity), [`formatQuantityToParts`](https://recipe-book.siraj.page/reference/core/formatting.md#formatquantitytoparts), [`formatIngredient`](https://recipe-book.siraj.page/reference/core/formatting.md#formatingredient), [`formatServings`](https://recipe-book.siraj.page/reference/core/formatting.md#formatservings), [`formatYield`](https://recipe-book.siraj.page/reference/core/formatting.md#formatyield), [`formatTemperature`](https://recipe-book.siraj.page/reference/core/formatting.md#formattemperature), [`formatDuration`](https://recipe-book.siraj.page/reference/core/formatting.md#formatduration), [`labelPack`](https://recipe-book.siraj.page/reference/core/labels.md#labelpack), [`parseRecipe`](https://recipe-book.siraj.page/reference/core/parsing.md#parserecipe), [`parseQuantity`](https://recipe-book.siraj.page/reference/core/parsing.md#parsequantity), [`parseIngredientLine`](https://recipe-book.siraj.page/reference/core/parsing.md#parseingredientline), [`createRecipeSchema`](https://recipe-book.siraj.page/reference/core/parsing.md#createrecipeschema), [`findRecipeJsonLd`](https://recipe-book.siraj.page/reference/core/schema-org.md#findrecipejsonld), [`fromJsonLd`](https://recipe-book.siraj.page/reference/core/schema-org.md#fromjsonld), and [`toJsonLd`](https://recipe-book.siraj.page/reference/core/schema-org.md#tojsonld), or the React parts [`<Recipe.Root>`](https://recipe-book.siraj.page/reference/react/root.md), [`<Recipe.Provider>`](https://recipe-book.siraj.page/reference/react/provider.md), [`<Recipe.Equipment>`](https://recipe-book.siraj.page/reference/react/equipment.md), and [`<Recipe.Nutrition>`](https://recipe-book.siraj.page/reference/react/nutrition.md), or hooks [`useRecipeState()`](https://recipe-book.siraj.page/reference/react/hooks.md#userecipestate) and [`useChecklistState()`](https://recipe-book.siraj.page/reference/react/checklist.md#usecheckliststate). When `toJsonLd` rejects an ingredient's quantity or one of its equivalents as the recipe gives it, the value's path comes after the name, as in `toJsonLd: ingredients[0].items[0].quantity: amount must be a finite number greater than 0, received 0.` for an amount of 0. A finite amount, or an end of a range, above 1e290 or between 0 and 1e-300 isn't checked, and where scaling or conversion makes one `Infinity` or 0, the message gives that `Infinity` or 0 and no path, as in `toJsonLd: amount must be a finite number greater than 0, received Infinity.`

| Message, after the name                                                                                                     | Fix                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| --------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `amount must be a finite number greater than 0, received NaN.`                                                              | [Check amounts from data](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `amount must be a number or a { min, max } range, received "2".`                                                            | Convert the string with `Number`, then [check it](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `range minimum (3) must not be greater than the maximum (2).`                                                               | Put the low end in `min`, or [check both ends](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data) when they come from data.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `range ends must be finite numbers greater than 0, received { min: 0, max: 2 }.`                                            | Check both ends, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `expected a quantity such as { amount: 2, unit: "cup" }, received null.`                                                    | Pass a [`Quantity`](https://recipe-book.siraj.page/reference/core/units.md#quantity) object.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `a quantity has no max; use amount: { min, max }, or formatServings or formatYield.`                                        | Write a quantity's range as `amount: { min, max }`, and [use `formatServings` or `formatYield`](https://recipe-book.siraj.page/errors/invalid_argument.md#use-formatservings-or-formatyield-not-quantity-functions) for servings and yields.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `factor must be a finite number greater than 0, received 0.`                                                                | Check the factor, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `scale must be a finite number greater than 0, received NaN.`                                                               | Check the scale, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| `the result must be a finite number greater than 0, but it is Infinity.`                                                    | Check the amount, and `scaleQuantity`'s factor, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data): the result is past the largest number, about 1.8e308, or below about 2.5e-324, where it rounds to 0 rather than up to the smallest number, 5e-324. `toSystem` also throws it when the measure it lands on is past the largest number.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `system must be "metric" or "us", received "US".`                                                                           | [Check the measurement system](https://recipe-book.siraj.page/errors/invalid_argument.md#check-the-measurement-system).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `temperature unit must be "C" or "F", received "K".`                                                                        | Use `'C'` or `'F'` for the [`Temperature`](https://recipe-book.siraj.page/reference/core/units.md#temperature) unit.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `target unit must be "C" or "F", received "celsius".`                                                                       | Pass `'C'` or `'F'` as the unit to convert to.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `value must be a finite number, received NaN.`                                                                              | Check the temperature's value, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `value out of range.`                                                                                                       | Check the temperature's value, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data): when a value beyond about ±2e307 °C is converted to °F or one beyond about ±3.6e307 °F is converted to °C, the arithmetic overflows to `Infinity` or `-Infinity` even when the result itself would be finite.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `minutes must be a finite number, 0 or more, received -1.`                                                                  | Check the duration, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `unitDisplay must be "short" or "long", received "narrow".`                                                                 | Pass a value the message lists, or leave the option out for its default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `fractions must be true or false, received "yes".`                                                                          | Pass a value the message lists, or leave the option out for its default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `rounding must be "kitchen" or "none", received "oven".`                                                                    | Pass a value the message lists, or leave the option out for its default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `rounding must be "kitchen", "oven", or "none", received "exact".`                                                          | Pass a value the message lists, or leave the option out for its default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `locale must be a language tag that Intl accepts, such as "en-US", received "en_US".`                                       | Use a tag `Intl` accepts, written with hyphens, as in `'en-US'`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `labels must be a label pack such as de from "@recipe-book/core/labels", received "de".`                                    | Import the pack from [`@recipe-book/core/labels`](https://recipe-book.siraj.page/reference/core/labels.md), or in a React app from [`@recipe-book/react/core/labels`](https://recipe-book.siraj.page/reference/react/labels.md#imports-on-cores-pages), and pass the object, not its name. A pack from `@recipe-book/react/labels` formats in client code. In a Server Component it's a client reference: on Next 15 and later, a formatting function given one throws this too, and on Next 14, Next throws "Cannot read Symbol exports. Only named exports are supported on a client module imported on the server." first. Either way, pass a pack from `@recipe-book/core/labels` in server code. For your own words, or a changed copy of a shipped pack, make the pack with `labelPack`. A spread copy of a pack isn't one, and TypeScript rejects it.                                                                                                                  |
| `labels must be an object, received "de".`                                                                                  | [`labelPack`](https://recipe-book.siraj.page/reference/core/labels.md#labelpack) throws it when given a value that isn't an object, such as a pack's name. Pass an object with your words, as `labelPack`'s example does. To use a shipped pack, import it instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           |
| `labels.language must be a language tag such as "de", received "German".`                                                   | [`labelPack`](https://recipe-book.siraj.page/reference/core/labels.md#labelpack) throws it when it makes the pack, and so does `labelPack` from [`@recipe-book/react/labels`](https://recipe-book.siraj.page/reference/react/labels.md#labelpack). Give `language` as a tag, such as `'de'`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `labels.units must be an object, received null.`                                                                            | `labelPack` throws it when it makes the pack. Give `units`, `durations`, `temperature`, and each entry in `units` and `durations` as an object, or leave it out.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `labels.durations.hour.long.other must be a string, received undefined.`                                                    | `labelPack` throws it when it makes the pack. Give the entry all four labels: `short.one`, `short.other`, `long.one`, and `long.other`. `temperature` takes `degree.one`, `degree.other`, `C`, and `F`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `expected servings such as { amount: 4, max: 6 }, received undefined.`                                                      | Pass a [`Servings`](https://recipe-book.siraj.page/reference/core/types.md#servings) object, and check that the recipe has `servings` first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                  |
| `expected a yield such as { amount: 24, unit: "cookie" }, received undefined.`                                              | Pass a [`Yield`](https://recipe-book.siraj.page/reference/core/types.md#yield) object, and check that the recipe has a `yield` first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                         |
| `max must be a finite number greater than amount (4), received 4. Leave max out for a single amount.`                       | Leave `max` out when it equals `amount`. Otherwise check it, as you would [an amount](https://recipe-book.siraj.page/errors/invalid_argument.md#check-amounts-from-data).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `unit must be a string such as "cookie", received undefined.`                                                               | Give the yield a `unit`, the word for what it makes, such as `'cookie'`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `plural must be a string, received 42.`                                                                                     | Write `plural` as a string, such as `'cookies'`, or leave it out.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `expected { ingredient, quantity? }, such as a resolved ingredient, received null.`                                         | Pass `{ ingredient }` with an [`Ingredient`](https://recipe-book.siraj.page/reference/core/types.md#ingredient). In React, pass the item from [`<Recipe.IngredientList>`](https://recipe-book.siraj.page/reference/react/ingredients.md#ingredientlist) or [`useRecipe().ingredients`](https://recipe-book.siraj.page/reference/react/hooks.md#userecipe).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `ingredient.name must be a string, received 42.`                                                                            | Parse the recipe with [`parseRecipe`](https://recipe-book.siraj.page/reference/core/parsing.md#parserecipe) first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `ingredient.plural must be a string, received 42.`                                                                          | Parse the recipe with [`parseRecipe`](https://recipe-book.siraj.page/reference/core/parsing.md#parserecipe) first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `ingredient.note must be a string, received 42.`                                                                            | Parse the recipe with [`parseRecipe`](https://recipe-book.siraj.page/reference/core/parsing.md#parserecipe) first.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `parseIngredientLine must be a function such as parseIngredientLine, received null.`                                        | Pass [`parseIngredientLine`](https://recipe-book.siraj.page/reference/core/parsing.md#parseingredientline), or leave the option out to read ingredient objects only.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `options must be an object such as { decimal: "," }, received ",".`                                                         | Pass the options in an object, as in `{ decimal: ',' }`. A locale string doesn't set them.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                    |
| `decimal must be "." or ",", received ";".`                                                                                 | Pass a value the message lists, or leave the option out for its default.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `units must be an object such as { cup: "cup-metric" }, received "metric".`                                                 | Pass an object with the units to read, or leave the option out for US cups and tablespoons.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `units.cup must be "cup" or "cup-metric", received "cups".`                                                                 | Pass a value the message lists, or leave the key out for the US cup.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `units.tbsp must be "tbsp" or "tbsp-au", received "tbsp-uk".`                                                               | Pass a value the message lists, or leave the key out for the US tablespoon.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   |
| `each key of units must be "cup" or "tbsp", received "pint".`                                                               | Remove the key. Only cups and tablespoons have regional sizes, as [`ParseQuantityOptions`](https://recipe-book.siraj.page/reference/core/parsing.md#parsequantityoptions) lists.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `recipe must be a parsed recipe, received a parse result instead of its data. …`                                            | Pass `result.data`, after checking `result.success`, as [Parse recipe input first](https://recipe-book.siraj.page/errors/invalid_argument.md#parse-recipe-input-first) shows. Only in development. In production, `<Recipe.Root>` gives the next row's.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       |
| `recipe must be a parsed recipe, received an object that parseRecipe hasn't normalized. …`                                  | [Parse recipe input first](https://recipe-book.siraj.page/errors/invalid_argument.md#parse-recipe-input-first).                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               |
| `expected options such as { recipe }, received undefined. …`                                                                | To read the state of the nearest `<Recipe.Root>`, call [`useRecipe()`](https://recipe-book.siraj.page/reference/react/hooks.md#userecipe) instead, or [`useChecklist()`](https://recipe-book.siraj.page/reference/react/checklist.md#usechecklist) for the ticks of a [`<Recipe.Checklist>`](https://recipe-book.siraj.page/reference/react/checklist.md#checklist). Otherwise pass `{ recipe }`. Only in development. In production, a hook called without options throws a `TypeError` instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `expected options such as { recipe }, received an object without a recipe property. Pass the parsed recipe as { recipe }.`  | Pass `{ recipe }`, not the recipe itself, to [`useRecipeState`](https://recipe-book.siraj.page/reference/react/hooks.md#userecipestate) or `useChecklistState`, or call `useRecipe()` in a Root. Only in development. In production, a hook given the recipe itself throws a `TypeError` instead.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                             |
| `labels must be a pack from @recipe-book/react/labels, such as de or labelPack({ servings: "Portions" }), received "de". …` | Import a pack from [`@recipe-book/react/labels`](https://recipe-book.siraj.page/reference/react/labels.md), or make one with its [`labelPack`](https://recipe-book.siraj.page/reference/react/labels.md#labelpack), and pass the pack itself. A plain object, or a copy of a pack, throws it too, because the parts write with the words a pack holds under a symbol key. TypeScript rejects a spread copy, such as `labels={{ ...de }}`, but not one made with `Object.assign` or `structuredClone`. A Server Component passes a pack from `@recipe-book/react/labels`, or one it imports by name from a `'use client'` module, as a client reference, which keeps it, but its props drop that key from a pack it makes or imports from any other module, such as core's `de` from `@recipe-book/react/core/labels`, so make your own pack in a `'use client'` module, as [Change one word](https://recipe-book.siraj.page/reference/react/labels.md#change-one-word) shows. |
| `labels must be a label pack.`                                                                                              | The production message for the row above. Fix it the same way.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `text must be a string, received 42.`                                                                                       | Pass a string, such as a [`Step`](https://recipe-book.siraj.page/reference/core/types.md#step)'s `text`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                      |
| `assumeTemperatureUnit must be "C" or "F", received "K".`                                                                   | Pass `'C'` or `'F'`, or leave the option out to keep temperatures without a unit as text.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                     |
| `html must be a string, such as await response.text(), received 42.`                                                        | Pass the string from `await response.text()`, not the `Response` or its `Promise`.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                            |

## Check amounts from data

`Number` returns `NaN` for text it can't read, such as `'½'`, so [`convert`](https://recipe-book.siraj.page/reference/core/units.md#convert) throws:

```ts {4,7}
import { convert } from '@recipe-book/core'

function cupsToMilliliters(text: string) {
  return convert({ amount: Number(text), unit: 'cup' }, 'ml')
}

cupsToMilliliters('½')
```

A finite amount greater than 0 can still throw, because `convert` throws when the result overflows to `Infinity` or underflows to 0, as it does for 1e308 cups. Check that the amount is from 1e-300 to 1e290, the range recipe input allows, before you convert it:

```ts {5}
import { convert } from '@recipe-book/core'

function cupsToMilliliters(text: string) {
  const amount = Number(text)
  if (Number.isNaN(amount) || amount < 1e-300 || amount > 1e290) return undefined
  return convert({ amount, unit: 'cup' }, 'ml')
}

cupsToMilliliters('0.5') // { amount: 118.29411825, unit: 'ml' }
cupsToMilliliters('½') // undefined
cupsToMilliliters('1e308') // undefined
```

## Use formatServings or formatYield, not quantity functions

A quantity has no `max`: its range is `amount: { min, max }`. A recipe's [`servings`](https://recipe-book.siraj.page/reference/core/types.md#servings) and [`yield`](https://recipe-book.siraj.page/reference/core/types.md#yield) write a range with `max` instead, as in `{ amount: 4, max: 6 }`. TypeScript rejects one where a quantity belongs, but with data typed `any`, the quantity functions, such as `convert`, throw for servings or a yield with a `max`:

```txt
RecipeBookError: convert: a quantity has no max; use amount: { min, max }, or formatServings or formatYield.
See https://recipe-book.siraj.page/errors/invalid_argument/
```

Use [`formatServings`](https://recipe-book.siraj.page/reference/core/formatting.md#formatservings) to print servings and [`formatYield`](https://recipe-book.siraj.page/reference/core/formatting.md#formatyield) to print a yield. [`resolveRecipe`](https://recipe-book.siraj.page/reference/core/resolving.md#resolverecipe) scales both with the ingredients.

## Check the measurement system

[`toSystem`](https://recipe-book.siraj.page/reference/core/units.md#tosystem) accepts only `'metric'` and `'us'`, in lowercase, so it throws for `'US'`:

```ts {3}
import { toSystem, type System } from '@recipe-book/core'

const system = new URLSearchParams('?system=US').get('system') as System

toSystem({ amount: 1.5, unit: 'cup' }, system)
```

Check the value instead of casting it, and fall back to a system you choose:

```ts {8}
import { toSystem, type System } from '@recipe-book/core'

function isSystem(value: unknown): value is System {
  return value === 'metric' || value === 'us'
}

const param = new URLSearchParams('?system=US').get('system')
const system = isSystem(param) ? param : 'metric'

toSystem({ amount: 1.5, unit: 'cup' }, system) // { amount: 354.88235475, unit: 'ml' }
```

## Parse recipe input first

[`<Recipe.Root>`](https://recipe-book.siraj.page/reference/react/root.md), [`useRecipeState()`](https://recipe-book.siraj.page/reference/react/hooks.md#userecipestate), and [`useChecklistState()`](https://recipe-book.siraj.page/reference/react/checklist.md#usecheckliststate) take a parsed recipe. Input typed `any`, such as the result of `response.json()`, gets past TypeScript even when you haven't parsed it:

```tsx {5,8}
import * as Recipe from '@recipe-book/react'

export default async function Page() {
  const response = await fetch('https://example.com/recipes/pancakes.json')
  const input = await response.json()

  return (
    <Recipe.Root recipe={input}>
      <Recipe.Image />
    </Recipe.Root>
  )
}
```

```txt
RecipeBookError: <Recipe.Root>: recipe must be a parsed recipe, received an object that parseRecipe hasn't normalized. Call parseRecipe() from @recipe-book/react/core and pass result.data.
See https://recipe-book.siraj.page/errors/invalid_argument/
```

Other input gets the same message with its kind after `received`, such as `received undefined.`, `received null.`, `received a string.`, or `received an array.`

Parse it with [`parseRecipe`](https://recipe-book.siraj.page/reference/core/parsing.md#parserecipe) and pass `result.data`:

```tsx {6,10}
import { parseRecipe } from '@recipe-book/react/core'
import * as Recipe from '@recipe-book/react'

export default async function Page() {
  const response = await fetch('https://example.com/recipes/pancakes.json')
  const result = parseRecipe(await response.json())
  if (!result.success) throw result.error

  return (
    <Recipe.Root recipe={result.data}>
      <Recipe.Image />
    </Recipe.Root>
  )
}
```

To parse in the browser instead, call `parseRecipe` in a Client Component, as [Parse in the browser](https://recipe-book.siraj.page/reference/react/root.md#parse-in-the-browser) shows. `useRecipeState()` and `useChecklistState()` check their `recipe` only in development.
