G
G
Grisha48002022-03-31 11:33:04
JavaScript
Grisha4800, 2022-03-31 11:33:04

How to split a string into two and output them as two different blocks?

There is a component:

function Product (props) {
    
        const {
            prod_id: id,
            prod_name : title,
            prod_status: status,
            prod_price: price,
            prod_oldprice : oldPrice,
        } = props;
    
    
        let oldPriceChecker = (oldPriceValue) => {
            if (oldPriceValue) {
                let oldPriceStr = oldPriceValue + ' zł';
                return(oldPriceStr);
            }else {
                return('');
            }
        }
    
    
        return (
        
        <div className="row">
          <div className="card">
            <div className="card-image">
              <img src="https://via.placeholder.com/150" />
            </div>
            <div className="card-content">
                <span className="card-title">{title}</span>
                <hr className="card_hr" />
                <p className="card_price" >{price} zł</p>
                <div className="card_price old_price">{oldPriceChecker(oldPrice)}</div>
                <div className="status">{status}</div>
            </div>
          </div>
      </div>
        ) 
    }

export {Product}

The data comes from this file .

Question: the variable prod_status: status can contain several values ​​(for example "new, promotion"), if so, you need to split it into two words and create a separate block for each, since now the whole line comes in the block.

Now the site looks like this (new,saleout) in one block:

6245671c21bfa575783180.png

You need this (new,saleout, etc. in separate blocks):

6245672e5fac3785714768.png

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0xD34F, 2022-03-31
@0xD34F

Instead let it be<div className="status">{status}</div>

{status.split(',').map(n => <div className="status">{n}</div>)}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question