1

I am trying to do this : setMyState(prevState=> {...prevState, name: e.nativeEvent.text });

While the console says src/components/addItem.js: Unexpected token And it doesn't work :( While using a js file .. I tried with .jsx too and same error :(. Also I found an answer here WebStorm error: expression statement is not assignment or call but it didn't solve my problem since when I run the app now it crashes exactly there ...

devserkan
  • 16,870
  • 4
  • 31
  • 47
Alessandro
  • 89
  • 1
  • 10

1 Answers1

6

If you use an arrow function and want to return an object you need to wrap your object with (). If you don't use, arrow function thinks {} is the body block. So, try using:

setMyState(prevState=> ({...prevState, name: e.nativeEvent.text }));
devserkan
  • 16,870
  • 4
  • 31
  • 47