Expanding the size of an array list item in React

I have an array containing various currencies:

const currencies =['USD','EUR','AUD','CNY','AED', 'AFN', 'ALL', 'AMD', 'ANG', 'AOA', 'ARS',
'AUD', 'AWG','AZN', 'BAM', 'BBD', 'BDT', 'BGN', ' BHD', 'BIF', 'BMD'
,'BND', 'BOB', 'BRL', 'BSD', 'BTN', 'BWP', 'BYN' ]

const firstCurrencies = currencies.slice(0,4)

Displayed below is the relevant code for my React component:

<div className="flex flex-col">   
                      <h3>Select a currency</h3>
                      <div className="flex flex-row z-40">
                        {firstCurrencies.map((firstCurrency,index) =>(
                          <div className="">
                            <div key={index} className="">
                            <span><Link to="#">{firstCurrency}</Link></span>
                            </div>
                            <hr></hr>
                          </div>  
                        ))}
                      </div>
                      </div>  

My question is: How can I add space after each currency item?

Currently, the display looks like this:

https://i.stack.imgur.com/i5v96.png

The goal is to have the currencies separated by spaces.

I attempted firstCurrencies.join(',') but it resulted in an error. Any suggestions?

Answer №1

Initially, if you encounter a visual glitch and have concerns about CSS, one way to address it is by adjusting paddings and margins. However, an alternative approach involves utilizing template strings, for example:

`${primaryCurrency} `

This method will help you achieve the desired outcome. I suggest attempting to rectify the problem through CSS adjustments rather than relying solely on template strings.

Answer №2

Adding space is a simple task that can be accomplished in various ways:


<span><Link to="#">{firstCurrency}{' '}</Link></span>

OR

<span><Link to="#">{`${firstCurrency} `}</Link></span>

OR

<span><Link to="#">{firstCurrency + ' '}</Link></span>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Maintain the div in its current location when zooming the map

I created a multi-layer map and added a div to it. However, the issue arises when I zoom in on the image, causing the div to change its position unexpectedly. For example, if I place the div over India and then zoom and drag the image, the div ends up in U ...

A guide on searching for information in a JSON document using PHP

In PHP, I am trying to retrieve an ID from the URL and then search for corresponding data in a JSON file, which will be displayed on the page. The URL structure will be and the code I will use is; $id = $_GET['id']; to assign the ID to a vari ...

Attempting to reach <p> from numerous web pages

Currently, I am working on a project where I need to extract text data from various websites. I have successfully managed to retrieve the text data using <p> tags. I would really appreciate any assistance with this task. Thank you! ...

Tips for altering a key within a tree-view:

I am working with a potentially infinite tree-view array: type Tree = { id: number; name: string; email: string; children: Tree[]; }; const tree: Tree[] = [ { id: 1, name: 'Truck', email: '@mail', children ...

Replacing jQuery.ajax from a different directory/domain - problem with using relative URLs

We are incorporating scripts from various sources and domains, including one that contains the definition for jQuery.ajax function. Calls to jQuery.ajax are being made from different places and domains using relative URLs, such as jQuery.ajax("my/relativ ...

Proper method of defining an action in Vuex

Do you think it's sufficient to create vuex-actions as simple as a1, without chaining then/catch calls? Or should I always go with creating Promises as in a2 (and also adding a reject branch)? Appreciate your insights... import Vue from 'vue& ...

What is the best way to integrate react-final-form with material-ui-chip-input in a seamless manner

Currently, I am utilizing Material UI Chip Input wrapped with Field from react-final-form. The main objective is to restrict the number of "CHIPS" to a maximum of 5. Chips serve as concise elements representing inputs, attributes, or actions. For more ...

The word "await" is a special reserved keyword used to call functions within an async

Currently utilizing async-await: Whenever the function run invokes findLateastVersion, even though run function is marked as async, an error message pops up stating await is a reserved word. The findLateastVersion method returns a promise and based on va ...

Tips for fixing flickering tables and bringing the scrollbar back to the top in your DataTable Forge viewer

Presently, I am working with a DataTable that consists of 100 rows and is being set up using lists. The lists dynamically change based on the selected name from a drop down. To achieve this, I use: $("#datatable").remove(); this.datatable = new Au ...

Find and filter the values in the range.getValues() array that correspond to the first element in apps script

In the spreadsheet provided, I have compiled a list of cities in different states of my country. This information will be utilized in a form; however, it is not feasible for users to sift through an extensive list of all cities listed. Therefore, I am look ...

react component failing to update after state change

The layout is not displaying correctly when the state of page changes. Whenever I click on a category link, it verifies if the link exists in the category list. Then, it should update the page state to 'category'. Similarly, clicking on a recipe ...

Struggling to publish a React application on GitHub pages, only to find that it keeps redirecting to the README file

Despite my best efforts and following tutorials, I am struggling to deploy my React App to GitHub pages using the gh-pages package. I have taken all the necessary steps such as: Installing the gh-pages package. Adding a homepage to the package.json in the ...

Larger Material UI icons contribute to significant Cumulative Layout Shift

I am facing an issue with my website that is built using React, Nextjs, and Material UI Every time the page loads, there is a significant Cumulative Layout Shift caused by an SVG Material UI Icon that initially renders large before adjusting to the styled ...

Avoiding GulpJs freezing with effective error handling techniques

I am currently in the process of converting my sass files to css and encountering some issues. Specifically, I am struggling with handling errors during the sass conversion process. Whenever there is an error, it causes gulp to hang, requiring me to rest ...

Using javascript to navigate back to the previous page without redirecting to the main page

When utilizing an iframe, I've implemented a back button that triggers the following JavaScript code when clicked: document.getElementById("myframe").contentWindow.history.go(-1); // back While this works as intended, if there are no previous pa ...

An unusual phenomenon in the controller hierarchy causing issues with accessing the parent scope in AngularJS

Recently delving into the world of angularjs, I encountered something perplexing that seemed like a glitch in the controller hierarchy when it comes to accessing the parent scope. Here are two code snippets that I believed should both function properly bas ...

Validating React components with TypeScript using an array structure where the field name serves as the key

Trying to implement form validation with React. I have a main Controller that contains the model and manages the validation process. The model is passed down to child controllers along with the validation errors. I am looking for a way to create an array ...

Attempting to send a POST request, only to be informed by the form that it is devoid of

I have been struggling with this problem for some time now. I implemented the category_create_post functionality in the categoryController, and everything seems to be set up correctly. I also configured the category_form.ejs to accept user input. However, ...

Currently experimenting with React Testing Library to test the validation messages within our useForm functionality

Currently, I am in the process of creating an RTL test to validate my form. My approach involves utilizing the useForm hook along with Yup for validation purposes. The specific scenario I aim to address is when a user triggers the Add button without filli ...

Verification is required for additional elements within the div block once a single checkbox has been selected

Currently, I am working in PHP using the CodeIgniter framework. I have a question regarding implementing a functionality with checkboxes and validation using jQuery. Here is the scenario I want to achieve: There are four checkboxes, and when one checkbox ...