Syntax: const {} = variableName, can anyone explain or point me into the right direction [duplicate]

First of all, this has nothing to do with React. It’s part of ECMAScript 6 (or JavaScript 2015, if you prefer).

What you see here is called Destructuring assignment:

const {girls, guys, women, men} = state;

// Is the same as

const girls = state.girls;
const guys = state.guys;
const women = state.women;
const men = state.men;


You’re probably going to encounter a similar pattern while studying React:

import { methodA, methodB } from "my-module";

In this case, you have a module called my-module that is exporting some functions. With the import {} from syntax, you choose which functions you want to import. Note that this is not a destructuring assignment, although it works similarly.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)