---
title: Variables in components
project: Flow
version: 11.1
section: development
language: en
license: MIT
url: https://totaljs.es/docs/flow/11-1/development/variables/
updated: 2026-11-19T10:58:54.144Z
---

# Variables in components

> Read FlowStream variables and global variables in your component and react when they change.

Users keep values such as addresses and names in variables, so they do not have to repeat them in every node. A FlowStream has its own variables, and Flow has global variables for all FlowStreams. See [Variables](/flow/11-1/guides/variables/).

## Fill in variables

`instance.replace(text)` replaces every `{key}` in the text with the value of that variable:

```js
var greeting = instance.replace(config.greeting);
// "{welcome}" becomes "Good morning" when the variable welcome is "Good morning"
```

Flow looks for the key in this order:

1. The variables of the FlowStream.
2. The global variables.
3. The secrets of the FlowStream, which the **Secrets** component creates.
4. `{hostname}`: the address of the FlowStream.
5. The data you pass as the second argument, for example `instance.replace('{welcome}, {name}', { name: 'Jane' })`.

A key that Flow cannot find stays in the text as it is, for example `{welcome}`.

Inside `instance.message`, `$.replace(text)` does the same, and reads the keys that are not variables from the message, for example `{data.name}` from `$.data.name`.

## Read variables directly

The variables are objects on the FlowStream:

```js
var a = instance.main.variables;    // variables of the FlowStream
var b = instance.main.variables2;   // global variables
```

## React when variables change

Flow calls these functions of every node when the user saves variables:

| Function | When |
|---|---|
| `instance.variables(variables)` | The variables of the FlowStream have changed. |
| `instance.variables2(variables)` | The global variables have changed. |

Prepare your values again in them. **Greeting** does it like this:

```js
instance.configure = function() {
	greeting = instance.replace(config.greeting);
};

instance.variables = instance.variables2 = function() {
	instance.configure();
};
```

After the user changes the FlowStream variable `welcome` from `Good morning` to `Good evening`, the next greeting is `Good evening, Jane!`, with no change to the node.
