Having trouble resolving this issue: Receiving a Javascript error stating that a comma was expected

I am encountering an issue with my array.map() function and I'm struggling to identify the problem

const Websiteviewer = ({ web, content, styles, design }) => {



const test = ['1' , '2']
  return (
      {test.map(item => {
        console.log(item);
      } )}
  ) 
}

export default Websiteviewer

This is a react component where I'm facing the 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 }]

Here is an image of the error

If you have any suggestions on how to resolve this issue, thank you in advance.

Answer №1

A common mistake is logging values inside JSX syntax, but you can avoid this by following these steps:

const WebsiteViewer = ({ web, content, styles, design }) => {
  const test = ["1", "2"];
  return (
    <>
      {test.map((item) => {
        console.log(item);
      })}
    </>
  );
};

export default WebsiteViewer

Answer №2

To properly handle your item within a fragment or div is crucial as only JSX can be returned in JSX files. Avoid logging values inside the return statement of JSX, as it is considered a poor practice.

const Websiteviewer = ({ web, content, styles, design }) => {
  const test = ["1", "2"];
  return (
    <>
      {test.map((item) => {
        console.log(item);
      })}
    </>
  );
};

export default Websiteviewer

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Is it possible to conceal the dates from past months in the datepicker plugin?

Currently, I am utilizing a datepicker tool from jQuery UI and adjusting its CSS to suit my requirements. My goal now is to hide any dates that are not currently active, specifically those displayed from other months. I am unsure if this can be achieved ...

`How can I activate caching for getServerSideProps in Next.js?`

We have implemented server-side rendering for a few pages and components. In an attempt to optimize performance, we have been experimenting with caching API responses. export async function getServerSideProps(context) { const res = await getRequest(API ...

The functionality of the onclick button input is not functioning properly in the Google

Here is some JavaScript code: function doClick() { alert("clicked"); } Now, take a look at this HTML code: <div > <table border="2" cellspacing="0" cellpadding="0" class="TextFG" style="font-family:Arial; font-size:10pt;"> <tr> <t ...

Verify the form data before triggering the ajax call with just one click

Ensuring that all required areas are completed in a form is crucial. The form needs to be validated properly to either reject the request with a message showing what information is missing, or submit it successfully... The rejection process works well as ...

Is it possible for me to convert my .ejs file to .html in order to make it compatible with Node.js and Express?

I have an index.html file and I wanted to link it to a twitter.ejs page. Unfortunately, my attempts were unsuccessful, and now I am considering changing the extension from ejs to html. However, this approach did not work either. Do .ejs files only work wit ...

The submit button is not reading the JavaScript file for validation and instead goes directly to my PHP file

**Hello, I'm new to Stack Overflow. My submit button is not reading the JavaScript file I created; instead, it goes straight to the PHP file without validating the input fields first in the JavaScript file. I've been stuck here for hours and can& ...

If the user decides to change their answer, the current line between the two DIVs will be removed

After clicking on two DIVs, I created two lines. Now, I am facing an issue with resetting the unwanted line when changing my answer. To reset the line, you can refer to the code snippet below: var lastSelection; ...

Why is my "webpack" version "^5.70.0" having trouble processing jpg files?

Having trouble loading a jpg file on the Homepage of my app: import cad from './CAD/untitled.106.jpg' Encountering this error message repeatedly: assets by status 2 MiB [cached] 1 asset cached modules 2.41 MiB (javascript) 937 bytes (rjavascript ...

I am not seeing a single cookie in my Next.Js frontend

During my development process, I utilized Django for the backend and Next.js for the frontend. As I tested my project on the local server 127.0.0.1, I noticed that there was a cookie containing _ga and csrftoken. https://i.sstatic.net/uvdcu.png However, ...

Attach the element to the bottom of the viewport without obstructing the rest of the page

My challenge is to create a button that sticks to the bottom of the viewport and is wider than its parent element. This image illustrates what I am trying to achieve: https://i.stack.imgur.com/rJVvJ.png The issue arises when the viewport height is shorte ...

Guide on sending server action form data to API request in Next.js

I'm currently working on a way to send form data to a fetch request using Server actions in Next.js 14. However, I've encountered an issue where the formData.get('code') doesn't appear to be reaching its destination and instead, I ...

VueJS1 flexible $parent.$parent method duration

Trying to utilize a parent function across multiple layers of nested child components. {{ $parent.$parent.testFunction('foo', 'bar') }} This approach currently functions, however, each time I navigate through levels in the hierarchy, ...

Utilizing jQuery and AJAX for submitting multiple POST requests

Experiencing a problem with posting data via AJAX using a drag and drop interface. The data is being sent to the POST URL as intended, but there's a recurring issue where the POST request occurs twice, causing the processing URL to handle the data aga ...

Trouble with AngularJS Smart Table when dealing with live data streams

Currently, I am facing a scenario where I am utilizing angularJs smart table for filtering. Here is the HTML code: <section class="main" ng-init="listAllWorkOrderData()"> <table st-table="listWorkOrderResponse"> <thead> ...

Dynamic scrolling feature for lists that moves horizontally

When working with a lengthy list, I encountered an issue with horizontal scrolling. It worked fine when the list was statically implemented as shown below. <div style="margin-top:100px;white-space: nowrap;"> <ul > <li style= ...

What are the benefits of fetching user data and storing it in the Context API with each request in Next.js?

In order to handle authenticated user data, I made the decision to utilize React's ContextAPI. By creating a custom App component and implementing a getInitialProps function, I was able to fetch user data from the backend. class MyApp extends App { ...

Utilize prop-types inheritance when a component is rendered via props

Is it possible to inherit prop-types when a component is rendered via the parents prop, without direct access to 'ChildProps' and 'Props' interface? Parent Component interface ChildProps { counter: number; setCounter: React.Dispat ...

What is the impact of memory on NodeJS performance?

Currently delving into a book on NodeJS, I stumbled upon an intriguing example: const express = require('express') const bodyParser = require('body-parser') const app = express() var tweets = [] app.listen('8000', '172 ...

What is the best way to patiently wait for lines to be printed out one by one

I am in the process of creating my own personal website with a terminal-style design, and I'm looking to showcase a welcome banner followed by a welcoming message. The effect I have in mind involves lines appearing individually from top to bottom and ...

The AutoComplete feature of MaterialUI Component fails to function properly even when there is available data

I am facing an issue with my component as it is not displaying the autosuggestions correctly. Despite having data available and passing it to the component through the suggestions prop while utilizing the Material UI AutoComplete component feature here, I ...