# React UI Tutorial: Buttons, Edit Boxes, Comboboxes, And Backend API Data
This tutorial focuses on the user interface part of React.
You will learn:
- What a React component is
- How to create a button
- How to create an edit box
- How to create a combobox
- How to store UI values with React state
- How to send data to a backend API
- How to read data from a backend API
The examples use your Tank Monitor backend:
```text
http://127.0.0.1:5000
```
## 1. What React Does
React helps you build a user interface with small pieces called components.
Example component:
```jsx
function App() {
return (
Tank Monitor
);
}
```
A component is just a JavaScript function that returns UI.
## 2. Important React Idea: State
State means data that can change while the page is open.
Examples:
- Text typed into an edit box
- Selected value in a combobox
- Data loaded from PostgreSQL through the backend API
- Loading or error messages
React uses `useState` for this:
```jsx
import { useState } from "react";
function App() {
const [tankName, setTankName] = useState("");
return (
setTankName(event.target.value)}
/>
);
}
```
Meaning:
```text
tankName
```
is the current value.
```text
setTankName
```
changes the value.
## 3. Button Example
A React button looks like normal HTML, but you attach a JavaScript function with `onClick`.
```jsx
function App() {
function handleButtonClick() {
console.log("Button was pressed");
}
return (
);
}
```
When the user presses the button, React runs:
```javascript
handleButtonClick()
```
## 4. Edit Box Example
An edit box is usually an ``.
```jsx
import { useState } from "react";
function App() {
const [operatorName, setOperatorName] = useState("");
return (
setOperatorName(event.target.value)}
/>
Current value: {operatorName}
);
}
```
Important parts:
```jsx
value={operatorName}
```
The input displays the React state value.
```jsx
onChange={(event) => setOperatorName(event.target.value)}
```
When the user types, React updates the state.
This is called a controlled input.
## 5. Number Edit Box Example
For numbers:
```jsx
import { useState } from "react";
function App() {
const [tankLevel, setTankLevel] = useState(0);
return (
setTankLevel(Number(event.target.value))}
/>
Tank level: {tankLevel}
);
}
```
`event.target.value` is normally text, so `Number(...)` converts it to a number.
## 6. Date And Time Edit Box
For tank full and empty time:
```jsx
import { useState } from "react";
function App() {
const [tankFullTime, setTankFullTime] = useState("");
return (
setTankFullTime(event.target.value)}
/>
{tankFullTime}
);
}
```
The browser shows a date/time picker.
## 7. Combobox Example
In HTML, a combobox is a `