0

I am new to react.js, I have a list of names to display as a button.

const test: React.FC<IProps> = () => {
const buttons1= () => {
    for(let i=0; i<good.length; i++){
            <TextButton
                label={good[i].name}
                onClick={}
            />
    }
};
return(
    <div>
       {buttons1()}
       <TextButton
           label={"test1"}
           onClick={}
        />
    </div>
)

}

This code is successfully compiled, but it the textbutton is not reflect in the page,

Thanks

1
  • use map for that instead of loop Commented Jul 20, 2021 at 3:23

2 Answers 2

1

You can use map, and here is the reference List and Keys

const test: React.FC<IProps> = () => {
    const buttons1 = () => {
        return good.maps((v,i) => {
            return (
                <TextButton
                    key={i}
                    label={v.name}
                    onClick={}
                />
            )
        })
    }

    return(
        <div>
        { buttons1() }
        <TextButton
            label={"test1"}
            onClick={}
         />
        </div>
    )
    
}
Sign up to request clarification or add additional context in comments.

Comments

0
const test: React.FC<IProps> = () => {
    const buttons1 = (good) => {
        return good.maps((v,i) => {
            return (
                <TextButton
                    key={i}
                    label={v.name}
                    onClick={}
                />
            )
        })
    }

    return(
        <div>
        { buttons1(good) }
        <TextButton
            label={"test1"}
            onClick={}
         />
        </div>
    )
    
}

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.