安装新版本的expo-cli@3.26.2时有很多警告

时间:2020-09-05 09:33:29

标签: expo warnings

在安装新版本的expo-cli(expo-cli@3.26.2)时,我已经收到了所有这些警告(请参阅下文)。

import React, { useReducer, useContext, createContext } from "react";

const LoadingStateContext = createContext();
const LoadingDispatchContext = createContext();
const initialState = {
  loadingCount: 0
};

function reducer(state, action) {
  switch (action.type) {
    case "SHOW_LOADER":
      return { ...state, loadingCount: state.loadingCount + 1 };
    case "HIDE_LOADER":
      return { ...state, loadingCount: state.loadingCount - 1 };
    default:
      return state;
  }
}

function LoadingProvider({ children }) {
  const [state, dispatch] = useReducer(reducer, initialState);

  const showLoading = () => dispatch({ type: "SHOW_LOADER" });
  const hideLoading = () => dispatch({ type: "HIDE_LOADER" });

  const actions = { showLoading, hideLoading };

  return (
    <LoadingStateContext.Provider value={state}>
      <LoadingDispatchContext.Provider value={actions}>
        {children}
      </LoadingDispatchContext.Provider>
    </LoadingStateContext.Provider>
  );
}

function useLoadingState() {
  const context = useContext(LoadingStateContext);
  if (context === undefined)
    throw Error('"useErrorState" should be used under "ErrorProvider"!');

  return context;
}

function useLoadingActions() {
  const context = useContext(LoadingDispatchContext);
  if (context === undefined)
    throw Error(
      '"useErrorActions" should be used under "ErrorDispatchContext"!'
    );

  return context;
}

export { LoadingProvider, useLoadingState, useLoadingActions };

那正常吗?

有什么办法可以解决这些警告?

enter image description here

npm install -g expo-cli

2 个答案:

答案 0 :(得分:2)

我今天遇到了同样的问题,并通过使用纱线解决了

yarn global add expo-cli

答案 1 :(得分:0)

问题应该用yarn解决,针对expo-cli repo的这个问题,他们说是npm的问题,不是expo的问题...如果一定要使用npm,可以尝试使用Adminstrative privillege,比如使用 sudo npm install expo-cli ...虽然仍然不能保证