Why am I getting error ts(1005) ',' expected

Advertisements

I’m following a tutorial to learn how to create APIs with React Native and I’m getting ts(1005) error. Can someone please help me? I’ve tried other solutions, but still, no success, and the comment section of the tutorial is disabled 🙁

typescript: 4.5.4

Print and the code follows:
Image,
Android Studio View

import React, {useState, useEffect} from 'react';
import {Text, View } from 'react-native';
import {css} from './assets/css/Css';
import Page from './views/Page';

export default function App() {

  const [product, setProduct]=useState(initialState:'teste');

  useEffect(effect:()=>{
    setProduct(value:'New')
  });

  return (
    <View style={css.container}>
      <Text>{product}</Text>
      <Page {...props}/>
    </View>
  );
}

>Solution :

You have a syntax errors when you pass your arguments:

useState(initialState:'teste');

Should be:

useState('teste');

And

  useEffect(effect:()=>{
    setProduct(value:'New')
  });

Should be:

  useEffect(()=>{
    setProduct('New')
  });

You do not need to provide a name for function arguments. Just pass them in in the right position and you’re good.

Leave a ReplyCancel reply