8.1. Swap in a UI5 Button
The counter already works: a plain <button> loads one pallet per click. Let's swap it for the UI5 one.
UI5 components need a ThemeProvider above them. In your own app you put it around <App /> in main.tsx, once (More exercises shows how). Here we wrap what App returns. Then replace <button> with <Button>. The props stay the same.
import { useState } from 'react';
import { ThemeProvider } from '@ui5/webcomponents-react/ThemeProvider';
import { Button } from '@ui5/webcomponents-react/Button';
import './styles.css';
export default function App() {
const [loaded, setLoaded] = useState(0);
return (
<ThemeProvider>
<main>
<h1>Shipment loading</h1>
<section>
<p>{loaded} / 10 pallets loaded</p>
<Button onClick={() => setLoaded(loaded + 1)}>
Load pallet
</Button>
</section>
</main>
</ThemeProvider>
);
}
You can also import everything from @ui5/webcomponents-react; one path per component loads less.
Need a hint?
- Keep the onClick as it is; only the tag changes.
- ThemeProvider becomes the outermost element, around <main>.
Click it. It looks like SAP now, and it still counts: a UI5 Button is just a React component, and onClick works the same way.