You have a bracket problem. If you want to return something without using brackets, you have to write the logic in one single line. The logic that you write in subsequent lines won't be validated inside that return statement.
Also, you need a parent element wrapped around your map statement to actually let the DOM know what to use as a parent container to hold all your map elements.
For example:-
return test.map(item => <div key={item}>{item}</div>)
in terms of what the DOM sees is :-
<div key={item}>{item}</div>
<div key={item}>{item}</div>
<div key={item}>{item}</div>
<div key={item}>{item}</div>
<div key={item}>{item}</div>
...
As you can see, the DOM has no idea what to use as a parent container to wrap all these <div>
statements in.
Therefore, you can use React.Fragment
or simply <></>
to wrap your map statement around.
The reason why you aren't seeing any error logs is because this isn't actually an error but a wrong way of writing your logic. The DOM does not know the output of your map statement. Therefore, it throws no errors. If however, you were to write multiple <div>
statements just like I mentioned above instead of a map statement, you would get errors while writing the code in a proper code editor, example: VS Code.
A proper way of writing your code would be:
import React from 'react';
import "./css/App.css"
const App= () =>{
const test=["1","2"];
return(
<>
{test.map(item => <div key={item}>{item}</div>)}
</>
);
}
export default App;