'React Native useState<Component>() syntax

I'm followint a tutorial where the following syntax for React.useState is in use:

import { getAuth, onAuthStateChanged, User } from 'firebase/auth' 
const [user, setUser] = React.useState<User>();

When I implement this code in my React Native app and run Expo I get the message that () is an unexpected token.

What does it mean? I studied different React guides to find a explanation for this but they did not explain the combination of useState and <>.



Solution 1:[1]

You are defining a type called User, this is for Typescript. Your file is in Javascript, therefore the syntax would be:

const [user, setUser] = React.useState(undefined);

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 Magofoco