Experimenting a bit with JSX at the moment and came across this idea :
I can do this:
import React from 'react'
const Test = () => {
return <div>Test</div>
}
export default Test
and then import this file somewhere else and do:
<Test />
Why doesn't the same work if I return arrays from my JSX files?
import React from 'react'
const Test = () => {
let arr = [
<div>Test 1</div>,
<div>Test 2</div>,
]
return arr;
}
export default Test
and then:
let [firstElement, secondElement] = Test();
return (
<div>
<firstElement />
</div>
)
In both cases, what I am trying to render is a pretty plain <div>. In the first case it's returned directly, in the second case it's destructured from an array. However, the second case doesn't work for me? Should it?
PS: I know I could do {firstElement} - but why not <firstElement />?