Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i define an enum in react native

Basically what I'm trying to achieve is send info to the server without quotations e.g Admin instead of "Admin", but as we all know Graphql will throw an error is the variable is not defined or is not in quotations.

like image 741
404notBrighton Avatar asked May 02 '18 12:05

404notBrighton


People also ask

How do I declare enum in react native?

we can create a enum like property as below: const adminEnum = { Admin: 'Admin'};

How do you define an enum?

An enum is a special "class" that represents a group of constants (unchangeable variables, like final variables). To create an enum , use the enum keyword (instead of class or interface), and separate the constants with a comma.

What is enum in Reactjs?

Enums or enumerations are a new data type supported in TypeScript. Most object-oriented languages like Java and C# use enums. This is now available in TypeScript too. In simple words, enums allow us to declare a set of named constants i.e. a collection of related values that can be numeric or string values.

How do you declare an enum in JavaScript?

The easiest way to define an enum would be to use Object. freeze() in combination with a plain object. This will ensure that the enum object cannot be mutated. const daysEnum = Object.


2 Answers

we can create a enum like property as below:

const adminEnum = { Admin: 'Admin'};

Hope I got the question right.

like image 105
Aman Gupta Avatar answered Oct 21 '22 10:10

Aman Gupta


you can use enum with typeScript in react-native like describe in the link

sample code is

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}
like image 29
Sultan Ali Avatar answered Oct 21 '22 10:10

Sultan Ali