How do i define an enum in react native

How do i define an enum in react native


8

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.

5 Answers
5


16

we can create a enum like property as below:

const adminEnum = { Admin: 'Admin'};

Hope I got the question right.

1


3

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

sample code is

enum Direction {
  Up = 1,
  Down,
  Left,
  Right,
}


0

I am using Enum in React as below method is Enum type in GraphQL

const result = apolloclient.mutate({
       mutation: reset_password,
       variables: {
           method: 'EMAIL',
           uuid: opts.uuid
       }
});


0

enum Pole {
East = 1,
West,
North,
South,
}


0

In a seperate class and a file.

  export enum TransportTypeEnum {
      OneWay = 0,
      Return = 1,
    }

import it to other class like

import {TransportTypeEnum} from '../enums/TransportTypeEnum';



Leave a Reply

Your email address will not be published. Required fields are marked *