小编Can*_*ver的帖子

如何删除所有意外添加到git系统的本地文件

我是“git”系统的新手。我可能犯了一个错误并将我所有的本地文件集成到“git”系统中。

当我说给我以下错误时,我使用“vs 代码编辑器”并丢弃所有更改:Git: fatal: You are on a branch yet to be born.

这是我在终端中使用“git status”命令时的样子:

warning: could not open directory '.Trash/': Operation not permitted
On branch master

No commits yet

Untracked files:
  (use "git add <file>..."
    to include in what will be committed)
  .. / .npm /
  .. / .viminfo
  .. / .vscode /
  .. / .zsh_history
  .. / Applications /
  . /
  .. / Documents /
  .. / Downloads /
  .. / Library /
  .. / Movies …
Run Code Online (Sandbox Code Playgroud)

git

3
推荐指数
1
解决办法
535
查看次数

怎么能 ?传递带有状态的函数以用于反应 useContext

尝试学习如何使用react hooks。我使用createContext并且我想将状态和函数一起传输到其他组件,但我需要有关如何执行此操作的帮助。我也想问这样做是否有意义。

事实上,我可以通过在我的情况下使用setState来更新状态,但是通过在上下文中定义一个函数,我认为在任何地方使用这个函数更有意义。我错了吗 ?

我的背景是:

export const ExpenseContext = createContext();

export const ExpenseProvider = props => {
  const [expense, setExpense] = useState(initialExpenses)

  const clearItems = () => {
    setExpense([])
  }

  return ( <
    ExpenseContext.Provider value = {
      [expense, setExpense],
      clearItems
    } > {
      props.children
    } <
    /ExpenseContext.Provider>
  )
}
Run Code Online (Sandbox Code Playgroud)

我想使用这个功能的组件:

const ExpenseList = () => {
  const [expense, setExpense] = useContext(ExpenseContext);
  const {
    clearItem
  } = useContext(ExpenseContext);

  //   const clearItems = () => { …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-hooks

2
推荐指数
1
解决办法
3454
查看次数

标签 统计

git ×1

javascript ×1

react-hooks ×1

reactjs ×1