This guide walks you through setting up your React project with Tailwind CSS, creating a multi-stage registration form with demo API integration, and deploying the project on GitHub Pages.
Make sure the following tools are installed on your system:
- Node.js (version 14.x or later)
- npm (Node Package Manager, comes with Node.js)
Open your terminal and run the following commands to check the versions:
node -v
npm -v
To manage multiple versions of Node.js, install FNM:
winget install Schniz.fnm
Configure FNM to switch Node versions when entering a directory:
fnm env --use-on-cd
Ensure npm is updated:
npm install -g npm
npm rebuild
Create your React app by running:
npx create-react-app cricket-website
Navigate to your project directory:
cd cricket-website
Add Tailwind CSS as a development dependency:
npm install -D tailwindcss
npx tailwindcss init
If you encounter issues with OpenSSL, set the legacy provider:
set NODE_OPTIONS=--openssl-legacy-provider
If there are problems with dependencies, clean them up:
del package-lock.json
rmdir /s /q node_modules
Reinstall all project dependencies:
npm install
To enable navigation in your application, install React Router:
npm install react-router-dom
Run your application locally:
npm start
In the tailwind.config.js file, add the following configuration:
module.exports = {
purge: ['./src/**/*.{js,jsx,ts,tsx}', './public/index.html'],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {},
},
variants: {
extend: {},
},
plugins: [],
};
Tailwind Directives: Add Tailwind directives to your src/index.css file:
@tailwind base;
@tailwind components;
@tailwind utilities;
In your RegistrationForm.js, update the handleSubmit function to send the form data to a demo API using Axios:
import axios from 'axios';
const handleSubmit = async (formData) => {
try {
const response = await axios.post('https://reqres.in/api/users', formData);
console.log(response.data); // Handle success (e.g., show a success message)
} catch (error) {
console.error('Error submitting the form:', error); // Handle error (e.g., show an error message)
}
};
To handle API requests, install Axios:
npm install axios
Install the GitHub Pages package for deploying your React application:
npm install gh-pages --save-dev
Add the following properties to your package.json file:
"homepage": "https://github.com/<your-username>/<your-repo-name>",
"scripts": {
"predeploy": "npm run build",
"deploy": "gh-pages -d build"
}
Replace with your GitHub username. Replace with the name of your GitHub repository.
Run the following command to deploy your React app to GitHub Pages:
npm run deploy
After deployment, you can view your live application at: (https://github.com/your-username/your-repo-name)