我不能明白爲什麼下面的方法行不通:出口做出反應常數
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