0

So while I was making my react native app, I tried to use an API from https://github.com/uport-project/react-native-uport-connect and there is a syntax that I've yet to understand.

May I know what does const { uport, MNID } mean from this code

import configureUportConnect from 'react-native-uport-connect'

const { uport, MNID } = configureUportConnect({ 
  appName: 'uPort Demo', 
  appAddress: '2oeXufHGDpU51bfKBsZDdu7Je9weJ3r7sVG', 
  privateKey:'<PRIVATE_KEY>', 
})

Im quite new to this and this code is placed on a seperate js file and im trying to export const { uport, MNID } so I could use it in my Components and im not sure if it's a variable, object or some js syntax. Thank you!

Aeriel
  • 65
  • 6
  • Hello @Aeriel and welcome to SO. As you can see your question answered before. Actually, you can find many answers on this subject. So, feel free to read them. This question is probably going to be closed. If you don't get the answer after reading the previous ones you can drop a comment here by mentioning any commenter. – devserkan Sep 15 '18 at 12:33
  • 1
    Got what I was looking for. Thank you :) – Aeriel Sep 15 '18 at 13:01

1 Answers1

1

This is called destructuring, and it means you are assigning your variables, not to the object that the function returns, but to the individual properties of that object, specifically the properties at the keys uport and MNID. The alternative syntax would be to say const variableName = // etc... and then you would access the properties like: variableName.uport.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment#Object_destructuring

Ben Steward
  • 2,338
  • 1
  • 13
  • 23