Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

return two elements inside the first part of ternary operator in JSX

I am using a function to show some components using the map function, i want to add an extra component staticlly, i am having trouble adding it in the first part of ternary operator in JSX.

Here is how i add the dynamic components with map function :

{
    this.state.loading ?
        <LoaderComponent/> :
        this.state.status ?
            this.state.config.map((input, key) => {
                return (this.getComponent(input, key))
            }) : ''
}

And here is how i tried to add the static component after the map function, i tried to add the two elements inside () but in vain

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

{
    this.state.loading ?
        <LoaderComponent/> :
        this.state.status ?
            (
                this.state.config.map((input, key) => {
                    return (this.getComponent(input, key))
                })
                <ExtraComponent/>
            ) : ''
}

>Solution :

You can use React Fragment.

   {
    this.state.loading ?
        <LoaderComponent/> :
        this.state.status ?
                <>
                   {this.state.config.map((input, key) => {
                    return (this.getComponent(input, key))
                    })}
                   <ExtraComponent/>
                </>
            : ''
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading