# Configure a component and reconfigure it later

> Give a component default options, override them in the config attribute, react in configure() and change them at runtime with reconfigure().

Framework: jcomponent20
Product: jComponent 20 (jcomponent@20)
Language: en
Content-SHA256: 0029f1b2c2a136827eb199e9ed2afef07a7637807acf316edd4f61f7011cad76
Snapshot: c0700e321579725c5cf4f5ace1ad7d2866d1b4f93c24a63c0b41b6b7998e976c
Sources: jcomponent20@3fedd009a277f50fddc608b97afbec553b67c51b
Review: not-recorded

The second argument of `COMPONENT()` holds the default options. The `config` attribute of the element overrides them, and the declaration reads the merged values from `config`. Implement `self.configure(key, value)` to react when an option is set or changed. At runtime `self.reconfigure('key:value;key2:value2')` (or `CONFIG(selector, config)` for many components) changes options and calls `configure` for each changed key.

```html public/index.html
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8" />
	<title>jComponent</title>
	<link rel="stylesheet" href="//cdn.componentator.com/spa.min@20.css" />
	<script src="//cdn.componentator.com/spa.min@20.js"></script>
</head>
<body>
	<ui-component name="badge" config="label:Sale"></ui-component>
	<ui-component name="badge" id="second"></ui-component>

	<script>

		COMPONENT('badge', 'color:blue;label:New', function(self, config) {

			self.make = function() {
				self.html('<b class="label"></b>');
				self.draw();
			};

			self.draw = function() {
				self.find('.label').text(config.label).css('color', config.color);
			};

			self.configure = function(key, value) {
				self.find('.label').length && self.draw();
			};

		});

	</script>

</body>
</html>
```
