Wednesday

How to use enums as props in react with typescript

myConstants.ts
export enum SIZE_TYPES {
  FULL = 'full',
  SMALL = 'small',
}

myClass.tsx
.
.
import { SIZE_TYPES } from '../static/myConstants';

interface Prop {
  sizeType: SIZE_TYPES;
}

class MyClass extends React.PureComponent<Prop> {
 .
 .
}

myClass2.tsx
.
.
import { SIZE_TYPES } from '../static/myConstants';

class MyClass2 extends React.PureComponent {
  render() {
    return (
        <MyClass sizeType={SIZE_TYPES.FULL}/>
    );
  }
}

No comments:

Post a Comment