0

I am currently building a project for fun , but I am only experienced in Java/Python/C/C++ and languages like that, not front end. I have been looking at other React Native projects and I just want to understand what is going on here.

const [username, setUsername] = useState([]);

const joinResponse = await meteredMeeting.join({

            name: username,

            roomURL: METERED_DOMAIN + "/" + roomName,
        })

setUsername(username)

I am confused about what kind of array is created with

const [username, setUsername] = useState([]);

and how a set function is called. What is going on here ?

  • 1
    If you're asking about the square brackets on the left hand side, that's [destructuring](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment); useState returns an array and element 0 is being assigned to the variable `username`, and element 1 to `setUsername`. If you want to learn what useState does, i recommend [react's documentation](https://react.dev/reference/react/useState) – Nicholas Tower Jul 04 '23 at 17:41

0 Answers0