meta data for this page
  •  

This is an old revision of the document!


Implementing Your Solution

1. Component Architecture

  1. Break down your UI into reusable components.
  2. Follow the Single Responsibility Principle: each component should do one thing well.

2. Setting Up Project Structure

  1. Organize your project with a clear folder structure:
   src/
     components/
     pages/
     services/
     styles/
     utils/

3. Using Material-UI

  1. Import and use Material-UI components in your project:
    1. Example: button
      1. The `import Button from '@mui/material/Button’;` line allows you to use the Button component
      2. This button can be used in the return statement as <Button />
   import Button from '@mui/material/Button';
   function App() {
     return (
       <div>
         <Button variant="contained">Hello World</Button>
       </div>
     );
   }

4. Version Control with Git

  1. Open GitHub Desktop
  2. Log in to your GutHub account
  3. Select your repository the top left
  4. Open your code by clicking ‘Open in VSCode'
  5. Create branches for each new feature
  6. Regularly commit your changes
  7. For more information: GitHub Documentation

5. Using React

  1. Create a New React Project
    1. In your terminal, navigate to the directory where you want to create your project.
    2. Run the following command to create a new React application. Replace my-first-react-app with your preferred project name.
  npx create-react-app my-first-react-app
  1. Navigate to Your Project Directory
  2. Move into your project directory
  cd my-first-react-app
  
 - Start the Development Server
   - In the project directory, start the development server by running. This command will open a new browser window/tab with your React app running at http://localhost:3000.
  npm start
  1. Understand the Project Structure
    1. Public Folder: Contains the index.html file. This is the entry point for your app.
    2. Src Folder: Contains the React components and styles.
    3. App.js: The main component.
    4. index.js: The entry point for the React application.
  2. Create Your First React Component
  3. Open Your Project in a Code Editor
  4. Use a code editor like VSCode and open the project directory.
  5. Edit the App Component
  6. Open src/App.js and replace the code with the following:
  import React from 'react';
  import './App.css';
  function App() {
    return (
      <div className="App">
        <header className="App-header">
          <h1>Hello, React!</h1>
          <p>This is my first React app.</p>
        </header>
      </div>
    );
  }
  export default App;
Routing

Routing enables you to have multiple different pages on your Web App. Those different pages need different routes or paths to be accessed. Therefore you need to define those routes, and pages to which they lead. Take a look into Routes React for better understanding of how this works.

  1. Routing of the project could be done as visible here:

- Save and View Changes

  1. Save App.js after making changes.
  2. View Changes in Browser
Component creation
 
 - Add a New Component
   - Create a New Component File
   - In the src folder, create a new file named MyComponent.js.
   - Define the New Component
   - Add the following code to MyComponent.js:
  import React from 'react';
  function MyComponent() {
    return (
      <div>
        <h2>This is a new component!</h2>
      </div>
    );
  }
  export default MyComponent;
  
 - Import and Use the New Component in App.js
 - Open src/App.js and modify it to include MyComponent:
  import React from 'react';
  import './App.css';
  import MyComponent from './MyComponent';
  function App() {
    return (
      <div className="App">
        <header className="App-header">
          <h1>Hello, React!</h1>
          <p>This is my first React app.</p>
          <MyComponent />
        </header>
      </div>
    );
  }
  export default App;
  1. Save and View Changes
    1. Save both App.js and MyComponent.js.
    2. View Changes in Browser
    3. The browser will reload, and you should see the new component's content below the original text.
React Hooks

Hooks are very important concept in React, because they are the core mechanism of tracking the state of data and content on the web pages.

Learn about hooks: How to manage state

Most useful hooks are:

useState()

  • Tracks the state of the data, the state of the variable to which it is refering
  • It has it's setState() method which should be used as the only way of changing the contents of the tracked variable

useEffect()

  • Tracks changes that are happening in the content, and is triggered if it notices a change in the variable that it was tracking
  • Tracked variable is put within the [ ] brackets at the right side
  • If the brackets are left empty, the useEffect hook will activate when the page is loaded, so it can be used for triggering the fetch of the data from the backend, or for doing certain logic for setting up the page
  • Otherwise, the useEffect will be triggered with the change of the variable within the brackets

useNavigate()

  • It is used for moving into another page, through code
  • This can be used when we want to transfer user to a different page, for example after they complete the process of registration, they should be sent to a Welcome, or a Login page

Add personality to your Web Application

To provide users with a nice experience while using your App, it is necessary to add a custom name and an icon to your app.

This information is visible in your browser tab, when your app is open and running.

As visible here:

  • name: ImpactXchange2024
  • icon: Flag of Malaysia

Setting up these two things helps your users find your application within all the other tabs that they have open.

To do this you should follow the next steps:

  1. Choose a suitable picture for your icon
    1. It should be something small, that does not require a lot of space and memory
  2. Rename the name of the picture into favicon.ico (with .ico extension) and put it in the Public folder of your project
  3. To change the name find index.html file of your project and change the text that is withing <title></title> tags