1

I have some data stored in an array:

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)

My React component relevant code here:

<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>  

What is the best way to add space to after the item.

At the moment its displaying like this:

enter image description here

The idea is to have the currencies separated by a space.

I have tried firstCurrencies.join(',') at the top but giving me an error.

Any tips?

1
  • 1
    I think, if you're using bootstrap you can add the class px-1 to the first div within the map's handler -> <div class="px-1"> or maybe pr-1 to avoid left padding. Commented Jan 27, 2021 at 7:56

2 Answers 2

1

at first, this is visual bug and questions with css^ so you can solve it using paddings and margins. But other way is using template strings, something like:

`${firstCurrency} `

that is the way to get your result. i recommend resolve your issue using css instead of template strings

Sign up to request clarification or add additional context in comments.

Comments

1

It's quite simple. Space can be added in the following ways:


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

OR

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

OR

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.