我不能明白为什么下面的方法行不通:出口做出反应常数
constants.js
import { createConstants } from '../utils';
export default createConstants(
'LOGIN_REQUEST',
'LOGIN_SUCCESS',
'LOGIN_FAILURE',
'LOGOUT',
'FETCH_DATA_REQUEST',
'RECEIVE_DATA'
);
utils.js
import React from 'react';
export function createConstants(...constants) {
return constants.reduce((acc, constant) => {
acc[constant] = constant;
return acc;
}, {});
}
接下来我要导入LOGIN_REQUEST例如,作为还原行动。
import { LOGIN_REQUEST, LOGIN_SUCCESS, LOGIN_FAILURE, LOGOUT } from '../constants';
,但我每次都输入常数越来越undefined
。 它只能当我定义是这样的:
export const LOGIN_REQUEST = 'LOGIN_REQUEST';
也许有人有一些想法?
如果你写了'module.exports = createConstants(...)',它可能会工作。 – Sulthan