# Props: where a value comes from

> Where a component's prop gets its value. The page first, then the value saved for the site, then the component's default.

A prop is a setting of a component: a heading, a link, a color. Three places can give it a value, and
the first one that has a value wins:

1. **The page.** What you write where the component is placed: an attribute on the tag, a property set
   by a script, or a `data-props` script inside the tag.
2. **The site.** A value saved in Taggor for this component on this site.
3. **The component.** The default its author declared.

## An example

A form component `my-form` declares a prop `heading` with the default `Contact us`. The site saved
`Talk to sales` for it:

```sh
npx taggor sites props set my-form heading "Talk to sales" --site SITE_ID
```

1. The page has `<my-form heading="Ask a question"></my-form>`. The visitor sees **Ask a question**:
   the page gave a value, and the page wins.
2. The page has `<my-form></my-form>`. The visitor sees **Talk to sales**: the page gave none, so
   the site's value is used.
3. The page has `<my-form></my-form>` and the site saved no value. The visitor sees **Contact us**:
   neither gave one, so the component's default is used.

So the same component can say one thing on most pages and another on one page: save the usual value
for the site, and write the exception on that page's tag.

## The page: three ways to write a value

```html
<!-- An attribute: the prop's name in kebab-case. -->
<my-form heading="Ask a question" submit-label="Send"></my-form>

<!-- A data-props script: one JSON object, for lists and objects, or for a CMS that strips attributes. -->
<my-form>
  <script type="application/json" data-props>
    { "heading": "Ask a question" }
  </script>
</my-form>
```

```js
// A property, from your own script.
document.querySelector("my-form").heading = "Ask a question";
```

When the same prop is written in more than one of these, the property wins, then the attribute, then
the `data-props` script.

A prop cannot be named like something every HTML element already has (`title`, `id`, `class`, `style`,
`hidden`, `lang` and the like): the build refuses it. Use `heading`, `label`, `productName`.

## The site: one saved value for both environments

A site keeps **one** set of saved props for a component, and both of its environments use it:
production and staging. There are no saved props per environment. To give staging a different value,
write it on the staging page, which wins over the saved one.

```sh
npx taggor sites props set COMPONENT PROP VALUE --site SITE_ID
```

The value is public (it is delivered to the page), so never save a password, a key or personal data.
`--as number`, `--as boolean` or `--as json` saves something other than text.

### When the two environments run different versions

Staging often runs a newer version than production. If you save a prop that only the newer version
declares, production cannot use it yet. Nothing breaks and nothing is lost: production leaves that
prop out and uses the component's default, and starts using the saved value by itself when it runs a
version that declares the prop. The CLI says so when you save, and `npx taggor sites show SITE_ID` lists,
for each environment, the saved props it is not using.

## Related

- [Sites and environments](https://taggor.dev/docs/sites.md): the two environments of a site and what each one shows.
- [Install the snippet](https://taggor.dev/docs/snippet.md): placing a component on a page.
- [The component contract](https://taggor.dev/docs/contract.md): how a component declares its props and their types.
