0

In one of my react apps I have to loop through an array.

function ActionTags({tags}) {
    let thisTagsHtml = (tags);
    //thisTagsHTML is a simple string, separated by ##  
    //string1##string2##string3##string4
    let tagsArray = thisTagsHtml.split('##');
    console.log(tagsArray);
    return (
        <div>
            {tagsArray.map(function(item, i){
                <span key = {i}>{item}</span>
            })}
        </div>
    );
}

This looks pretty simple. However, nothing is returned from the function. Any idea where my mistake is? Thank you.

1 Answer 1

1

you missed return keyword before the statement <span key = {i}>{item}</span>

Like this :

function ActionTags({tags}) {
    let thisTagsHtml = (tags);
    //thisTagsHTML is a simple string, separated by ##  
    //string1##string2##string3##string4
    let tagsArray = thisTagsHtml.split('##');
    console.log(tagsArray);
    return (<div>
    {
        tagsArray.map(function(item, i) {
           return <span key={i}>{item}</span>
        });
    }
    </div>);
}
Sign up to request clarification or add additional context in comments.

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.