reactjs 未捕获的类型错误不是react js中的函数或可迭代对象

ymdaylpp  于 2023-01-17  发布在  React
关注(0)|答案(1)|浏览(118)

它显示的redux不是react js中的一个函数或可迭代函数。我检查了所有的代码,看到了一些其他可迭代函数,但没有对我的错误的答案。https://i.stack.imgur.com/E4IkQ.png
这是我的准则。
GlobalState.js

import React, { createContext, useReduer } from 'react';
import AppReducer from './AppReducer';

const initialState = {
    transactions: [
        { id: 1, text: 'Flower', amount: -20 },
        { id: 2, text: 'Salary', amount: 300 },
        { id: 3, text: 'Book', amount: -10 },
        { id: 4, text: 'Camera', amount: 150 }
    ]
}

export const GlobalContext = createContext(initialState);

export const GlobalProvider = ({ children }) => {
    const [state, dispatch] = useReduer(AppReducer, initialState);

    return (<GlobalContext.Provider value={{
        transactions: state.transactions
    }}>
        {children}
    </GlobalContext.Provider>);
}

AppReducer.js

/* eslint-disable import/no-anonymous-default-export */
export default (state, action) => {
    switch(action.type) {
        default:
            return state;
    }
}

App.js

import React from 'react';
import './App.css';
import { Header } from './components/Header';
import { Balance } from './components/Balance';
import { IncomeExpenses } from './components/IncomeExpenses';
import { TransactionList } from './components/TransactionList';
import { AddTransaction } from './components/AddTransaction';
import { GlobalProvider } from './context/GlobalState';

function App() {
  return (
    <GlobalProvider>
      <Header />
      <div className='container'>
          <Balance />
          <IncomeExpenses />
          <TransactionList />
          <AddTransaction />
      </div>
    </GlobalProvider>
      
  );
}

export default App;
kcugc4gi

kcugc4gi1#

我看到这个帖子几天后仍然开放,所以我发布我的评论作为关闭它的答案。
从你的代码中,我看到你输入了useReduer,而不是useReducer。你能修复它并再试一次吗?如果它仍然中断,请编辑帖子

相关问题