How to define constants in ReactJS

前端 未结 5 2244
无人共我
无人共我 2021-02-03 18:42

I have a function that maps text to letters:

sizeToLetterMap: function() { 
     return {
                small_square: \'s\',
                large_square: \'q\         


        
5条回答
  •  一个人的身影
    2021-02-03 19:03

    well, there are many ways to do this in javascript just like other says. I don't think there's a way to do it in react. here's what I would do:

    in a js file:

    module.exports = {
        small_square: 's',
        large_square: 'q'
    }
    

    in your react file:

    'use strict';
    
    var Constant = require('constants');
    ....
    var something = Constant.small_square;
    

    something for you to consider, hope this helps

提交回复
热议问题