'can't resolve this error: Javascript error ',' expected
I have an error on this array.map() and i can't figure what is the problem
const Websiteviewer = ({ web, content, styles, design }) => {
const test = ['1' , '2']
return (
{test.map(item => {
console.log(item);
} )}
)
}
export default Websiteviewer
this is the react component and i have this following error ->
[{ "resource": "/c:/path/WebsiteViewer.js", "owner": "typescript", "code": "1005", "severity": 8, "message": "',' expected.", "source": "ts", "startLineNumber": 18, "startColumn": 12, "endLineNumber": 18, "endColumn": 13 }]
if you have any idea how to solve this. thanks
Solution 1:[1]
It is not a good practice to log value inside JSX syntax. But you can prevent from your syntax error like this
const Websiteviewer = ({ web, content, styles, design }) => {
const test = ["1", "2"];
return (
<>
{test.map((item) => {
console.log(item);
})}
</>
);
};
export default Websiteviewer
Solution 2:[2]
Return your item inside a fragment or a div since you can only return JSX in JSX files.Logging value inside return of JSX is a bad approach though.
const Websiteviewer = ({ web, content, styles, design }) => {
const test = ["1", "2"];
return (
<>
{test.map((item) => {
console.log(item);
})}
</>
);
};
export default Websiteviewer
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mike 'Pomax' Kamermans |
| Solution 2 | Ritik Banger |
