ReactJS-based Application for Exchanging Currencies
In this article, we'll walk through the process of creating a currency converter app using React Functional Components, React Hooks, Axios for API calls, and JavaScript ES6. This project is part of the ReactJS-Projects series and utilises the 'currency-api' for fetching a list of all available currencies.
**Overview**
The app consists of three sections: user input, a conversion menu, and a display section. Users can input an amount and choose their desired currencies from the dropdown menus. Upon selecting the 'Convert' button, the app calculates the converted currency based on the latest exchange rates fetched from the API. The project's output is displayed in a clean and simple UI, styled using easy-to-understand CSS.
**Example: App.js**
```jsx // ... (import statements omitted for brevity)
function App() { // ... (state variables and useEffect hook setup omitted for brevity)
const convertCurrency = () => { // ... (conversion logic omitted for brevity) };
return ( // ... (JSX structure omitted for brevity) ); }
export default App; ```
**Example: App.css**
```css // ... (CSS styles omitted for brevity) ```
**Steps to Run the Application**
1. **Setup React Environment**
Make sure you have Node.js and npm installed. Then create a new React app using:
```bash npx create-react-app currency-converter cd currency-converter ```
2. **Install axios**
Within your project directory, install Axios:
```bash npm install axios ```
3. **Replace default App files**
Replace the contents of `src/App.js` and `src/App.css` with the provided code above.
4. **Run the App**
Start the React development server:
```bash npm start ```
Your currency converter will be running typically at `http://localhost:3000`.
With this currency converter app, users can effortlessly convert currencies using real-time exchange rates from an accessible API. The project demonstrates best practices in React development, making it an excellent learning resource for those looking to enhance their React skills.
This project also incorporates a 'trie' data structure to optimize searching for available currencies from the 'currency-api'. This trie implementation efficiently manages the large number of currencies by using a prefix tree to perform fast look-up operations as users select their desired currencies from the dropdown menêus. Moreover, this trie technology is an integral part of the React technology stack utilized within the app's architecture.