-2
let a=50, b=150; 
let elements= [ { data: { id: 'root ', label: 'SANIANJUM' }, position: { x: a, y: b } }, ]; let username = "SANIANJUM"; 
elements.push({ data: { id: 'two', label: 'Node 2' }, position: { x: 150, y: 100 } },) 
elements.push({ data: { source: 'one', target: 'two', label: 'Edge from Node1 to Node2' } },);

//can't push to my elements array ![Using async to fetch data here][2] [2]: https://i.stack.imgur.com/R3R7O.png

  • Do you have more context? Just an image, suspected error and code isn't gonna cut it. The code shown doesn't look likely to be the source of the error anyways. – kelsny Sep 11 '22 at 05:12
  • 1
    Please add some more details i.e. error message/stack trace and complete code from where you are getting an error. – Ankit Singh Sep 11 '22 at 05:17
  • Unable to push to my elements ayyay , throws this error – SANIA ANJUM Sep 11 '22 at 05:19

1 Answers1

0

The React.js error "Expected an assignment or function call and instead saw an expression" occurs when we forget to return a value from a function. To solve the error, make sure to explicitly use a return statement or implicitly return using an arrow function.

Here is the screenshot of issue

Ankit Singh
  • 127
  • 2
  • return ; returnig this at the end of function call – SANIA ANJUM Sep 11 '22 at 05:31
  • this error is coming from the function which you are using just below "elements.push({ data: { source: 'one', target: 'two', label: 'Edge from Node1 to Node2' } },);" Not when you are pushing an element - so what ever you are returning from the function assign that to any variable/const - then use it. – Ankit Singh Sep 11 '22 at 05:41
  • (async () =>{ const repositoriesResponse = await octokit.request("GET /user/repos"); })(); // using async to fetch repositories of my github - using arrow function to return this – SANIA ANJUM Sep 11 '22 at 06:01