1

I want to create an array of Buttons which will be rendered by React. The Button is a standard HTML element.

let buttons: HTMLButtonElement[] = []
for(let [key, value] of SomeMap) {
    buttons.push(<button onClick={...}>{value}</button>)
}

But this gives me

Argument of type 'Element' is not assignable to parameter of type 'HTMLButtonElement'.   Type 'ReactElement<any, any>' is missing the following properties from type 'HTMLButtonElement': disabled, form, formAction, formEnctype, and 300 more.

and

Type 'HTMLButtonElement[]' is not assignable to type 'ReactNode'. Type 'HTMLButtonElement[]' is not assignable to type 'ReactFragment'. The types returned by 'Symbol.iterator.next(...)' are incompatible between these types. Type 'IteratorResult<HTMLButtonElement, any>' is not assignable to type 'IteratorResult<ReactNode, any>'. Type 'IteratorYieldResult' is not assignable to type 'IteratorResult<ReactNode, any>'. Type 'IteratorYieldResult' is not assignable to type 'IteratorYieldResult'. Type 'HTMLButtonElement' is not assignable to type 'ReactNode'. Type 'HTMLButtonElement' is missing the following properties from type 'ReactPortal': key, props How woould I create an empty array that can hold buttons in React and TypeScript?

1 Answer 1

1

This can be done with

let buttons: JSX.Elements[] = []
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.