Issue in react context api

Facing issues in react context api, getting undefined while transferring anything using context api.error
getting this error, getting undefined when sending functions through context api.

*** **Contextr.js**

import React, { useReducer, createContext } from "react";
import contextReducer from "./contextReducer";

const initialState = [];

export const ExpenseTrackerContext = createContext(initialState);

export function Provider({ children }) {
  const [transactions, dispatch] = useReducer(contextReducer, initialState);`enter code here`

  const deleteTransaction = (id) =>
    dispatch({ type: "DELETE_TRANSACTION", payload: id });
  const addTransaction = (transaction) =>
    dispatch({ type: "ADD_TRANSACTION", payload: transaction });
 

  return (
    <ExpenseTrackerContext.Provider
      value={{
        deleteTransaction,
        addTransaction,
        transactions,
      }}
    >
      {children}
    </ExpenseTrackerContext.Provider>
  );
}

60 thoughts on “Issue in react context api”

Leave a Comment