import { useEffect, useState } from 'react' import './App.css' // Note: this import works only after generating the frontend code through the Platformatic CLI import { getMovies, createMovie, updateMovie, setBaseUrl } from './platformatic-generated-code/api/api' setBaseUrl('http://localhost:9999') function App () { const [movies, setMovies] = useState>>([]) const [newMovie, setNewMovie] = useState>>() async function onCreateMovie () { const newMovie = await createMovie({ title: 'Harry Potter' }) setNewMovie(newMovie) } async function onUpdateMovie () { if (!newMovie || !newMovie.id) return const updatedMovie = await updateMovie({ id: newMovie.id, title: 'The Lord of the Rings' }) setNewMovie(updatedMovie) } useEffect(() => { async function fetchMovies () { const movies = await getMovies({}) setMovies(movies) } fetchMovies() }, []) return ( <>

Vite + React

Testing out the frontend code automatically generated by the Platformatic CLI.

You can find more details about the topic at:  https://docs.platformatic.dev/docs/cli

Movies

{movies.length === 0 ? ( 'No movies yet' ) : ( )} {newMovie &&
Title: {newMovie.title}
} ) } export default App