文件树缩减器中的状态未定义
state undefined in file tree reducer
我只想 return 来自我的减速器的对象数组,但是 useSelect()
return 未定义
reducer/directories/index.js:
export * from './reportDir'
reducer/directories/reportDir.js:
const reportDir = [
{
type: 'cat',
name: 'گزارش ها',
childrens: [
{
type: 'folder',
name: 'گزارش های اپراتور',
childrens: [
{type: 'file', name: 'گزارش شنود', route: '/listen', id: 1}
]
},
{
type: 'folder',
name: 'گزارش مالی',
childrens: [
{type: 'file', name: 'مالی', id: 2}
]
}
]
}
]
const reportDirReducer = (state = reportDir) => {
return state
}
export default reportDirReducer
reducer/index.js:
import { combineReducers } from 'redux'
import newTabReducer from './newTabReducer'
import fileReducer from './fileReducer'
import tableReducer from './tableReducer'
import { authentication } from './authenticationReducer';
import { alert } from './alertReducer';
import { listen } from './reportOpReducer';
import { reportDirReducer } from './directories';
export default combineReducers({
newTabReducer, fileReducer, authentication,
tableReducer, alert, listen, reportDirReducer
})
这是我为我的 React 应用程序创建的一个简单目录路径,我不知道为什么我从 reportDirReducer
得到 undefined
?
您的 reducer/index.js
文件正在 './directories'
中寻找名称为 reportDirReducer
的命名导出。该变量不存在,因为 reducer 是默认导出,而不是命名导出。使用 export *
.
时,它基本上会“丢失”
在你的reducer/directories/index.js
中,改用这个:
export { default as reportDirReducer } from './reportDir';
我们从 './reportDir'
导入默认导出,这是减速器。然后我们将其重新导出为命名导出 reportDirReducer
.
另一种解决方案是保持 reducer/directories/index.js
文件与现在相同,并将 reducer/directories/reportDir.js
更改为使用命名导出而不是默认导出。
export const reportDirReducer = (state = reportDir) => {
return state;
};
我只想 return 来自我的减速器的对象数组,但是 useSelect()
return 未定义
reducer/directories/index.js:
export * from './reportDir'
reducer/directories/reportDir.js:
const reportDir = [
{
type: 'cat',
name: 'گزارش ها',
childrens: [
{
type: 'folder',
name: 'گزارش های اپراتور',
childrens: [
{type: 'file', name: 'گزارش شنود', route: '/listen', id: 1}
]
},
{
type: 'folder',
name: 'گزارش مالی',
childrens: [
{type: 'file', name: 'مالی', id: 2}
]
}
]
}
]
const reportDirReducer = (state = reportDir) => {
return state
}
export default reportDirReducer
reducer/index.js:
import { combineReducers } from 'redux'
import newTabReducer from './newTabReducer'
import fileReducer from './fileReducer'
import tableReducer from './tableReducer'
import { authentication } from './authenticationReducer';
import { alert } from './alertReducer';
import { listen } from './reportOpReducer';
import { reportDirReducer } from './directories';
export default combineReducers({
newTabReducer, fileReducer, authentication,
tableReducer, alert, listen, reportDirReducer
})
这是我为我的 React 应用程序创建的一个简单目录路径,我不知道为什么我从 reportDirReducer
得到 undefined
?
您的 reducer/index.js
文件正在 './directories'
中寻找名称为 reportDirReducer
的命名导出。该变量不存在,因为 reducer 是默认导出,而不是命名导出。使用 export *
.
在你的reducer/directories/index.js
中,改用这个:
export { default as reportDirReducer } from './reportDir';
我们从 './reportDir'
导入默认导出,这是减速器。然后我们将其重新导出为命名导出 reportDirReducer
.
另一种解决方案是保持 reducer/directories/index.js
文件与现在相同,并将 reducer/directories/reportDir.js
更改为使用命名导出而不是默认导出。
export const reportDirReducer = (state = reportDir) => {
return state;
};