MANUAL
Getting started with a React project
01 / WHAT IT IS
Building blocks for your screen.
React is a JavaScript library from Meta for building screens from individual components, such as a button, a menu or a form. With Vite, you can set up a new React project in just a few minutes.
01 / Creating a new project
Open the terminal in the folder where you store your projects:
npm create vite@latest mijn-app -- --template react-ts
react-ts creates a project using TypeScript. Would you prefer plain JavaScript? If so, use --template react.
02 / Installation and start-up
cd mijn-app
npm install
npm run dev
Open the address that appears, usually http://localhost:5173.. To stop the process, press Ctrl + C.
02 / THE FOLDERS
What’s where.
03 / The most important files
- index.html: the only HTML page. React populates it.
- src/main.tsx: this is where the app starts.
- src/App.tsx: the first section. Edit the text and save; you’ll see the changes straight away in the browser.
- public/: images and files that will be published online exactly as they are.
- package.json: the list of packages and commands.
04 / A component
A component is a function that returns a section of the screen:
function Welkom() {
return <h1>Welkom op mijn app</h1>;
}
You then use it as <Welkom />.
03 / PUT ONLINE
Build the app.
05 / Construction
npm run build
Vite places the finished files in the dist folder. You then upload that folder to your hosting account.
06 / View locally first
npm run preview
07 / Committing to Git
Vite automatically creates a .gitignore file containing node_modules and dist. Add the rest of the project to Git. See the ‘Working with Git’ manual.
04 / WORKING WITH AI
Ask your assistant.
08 / Documentation
The official documentation can be found on react.dev and vite.dev. Ask your AI assistant to use these instead of outdated examples. Many examples online still use Create React App, which is no longer maintained.
09 / A task for your AI assistant
"In this React project, create a contact form with fields for name, email and message. Use the documentation from react.dev. Show which files you are modifying and ask for permission before installing new packages."
Good to know
Any visitor can read everything contained within a React app. Never include API keys or passwords there, not even in a file beginning with VITE_.