Skip to main content
Frontend tutorial

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.

Work locally

You need Node.js 24, pnpm and Git (how to set them up). Clone this step’s starting code:

git clone --depth 1 \
--branch lesson-08-01-provider-and-button-start-v6 \
https://github.com/adam-zielonka/frontend-tutorial.git \
08-01-provider-and-button
cd 08-01-provider-and-button
pnpm install --frozen-lockfile
pnpm dev

To keep your own commits: git switch -c my-work.

Browse the source on GitHub (opens in a new tab)

Bring your browser edits

Choose Download my files in the ⋯ menu. It saves the lesson’s files as JSON. Stop the local server with Ctrl+C, copy the download into the project folder and run:

node import-draft.mjs ./08-01-provider-and-button-my-files.json
pnpm dev

The import replaces the project’s exercise files, so commit or back up local edits first.

Loading this step’s code…
Starting the live preview…