打字稿,上下文提供者和详尽的下降警告

在我的react-typescript应用程序中,我尝试使用上下文提供程序,该提供程序封装属性和方法并将其公开给使用者:

interface StockPrice {
  val: number;
  fetch: () => void;
}

const initialStockPrice = {val: NaN, fetch: () => {}};

type Action = {
  type: string;
  payload: any;
};

const stockPriceReducer = (state: StockPrice, action: Action): StockPrice => {
  if (action.type === 'fetch') {
    return {...state, val: action.payload};
  }
  return {...state};
};

const myContext = React.createContext<StockPrice>(initialStockPrice);

const StockPriceProvider: React.FC = ({children}) => {
  const [state, dispatch] = React.useReducer(
    stockPriceReducer,
    initialStockPrice
  );
  const contextVal  = {
    ...state,
    fetch: (): void => {
      setTimeout(() => {
        dispatch({type: 'fetch', payload: 200});
      }, 200);
    },
  };
  return <myContext.Provider value={contextVal}>{children}</myContext.Provider>;
};

const StockPriceConsumer: React.FC = () => {
  const stockPrice = useContext(myContext);
  let val = stockPrice.val;
  useEffect(() => {
    stockPrice.fetch();
  }, [val]);
  return <h1>{stockPrice.val}</h1>;
};

问题是有关StockPriceConsumer中useEffect的警告

React Hook useEffect缺少依赖项:“ stockPrice”。要么   包括它或删除依赖   array.eslint(react-hooks / exhaustive-deps)

对我而言,将stockPrice(基本上是提供程序的API)包含在useEffect的依赖关系中没有任何意义。仅包含股价的实际值以防止对useEffect函数的无限调用是有意义的。

问题:我尝试使用的方法有什么问题,还是可以忽略此警告?