In Bloatless-React, States are the foundation of how reactivity is implemented. Similar to many frameworks, a State can hold a value and triggers the UI to update when it changes. However, **subscriptions have to be made manually** due to the minimal nature of this project.
```TypeScript
// Import
import*asReactfrom'bloatless-react';
// Create States
constname=newReact.State("John Doe");// will be State<string>
constage=newReact.State(69);//will be State<number>
// Get value
console.log(name.value);
// Subscribe
age.subscribe(newAge=>console.log(`Age changed to ${newAge}`));
// Set value
name.value="Jeff";
```
## Proxy States
A Proxy State is a State based on multiple other States. This reduces code and can increase performance.
```TypeScript
// Import
import*asReactfrom'bloatless-react';
// Create States
constname=newReact.State("John Doe");// will be State<string>
constage=newReact.State(69);//will be State<number>
// Proxy State
constsummary=React.createProxyState([name,age],()=>`${name.value} is ${age.value} years old.`)
A `ListState<T>` is a State whose value is a `Set<T>`. A ListState allows specific subscriptions to detect when items get added and removed. This allows dynamic lists to run efficiently.
For a minimalist stylesheet, I'd recommend checking out my project called [carbon-mini](https://github.com/marlon-erler/carbon-mini/).
Bloatless React provides a modified polyfill for the React API. This means that **you can use JSX** almost like you would in a React project. Additional functionailiy is implemented through directives, similar to Svelte:
The `subscribe:<property>` directive subscribes to a State and changes a property of the element. Use this for properties available via the DOM model (ie. innerText, innerHTML).
The `toggle:<attribute>` directive toggles attributes on the HTML element without assigning a value. This is useful for the `disabled` attribute. You can use states or normal variables.
The `bind:<property>` directive acts like a combination of `subscribe:<property>` and `on:input`. It binds the element's property to the state bi-directinally.
```TypeScript
constname=newReact.State("John Doe");
// Both inputs will be in sync
<inputbind:value={name}></input>
<inputbind:value={name}></input>
```
## Dynamically Creating and Removing Child Elements
The `subscribe:children` directive subscribes to a ListState and adds/removes child elements accordingly.