React函数组件中如何使用useContext钩子?
- 内容介绍
- 文章标签
- 相关推荐
本文共计1073个文字,预计阅读时间需要5分钟。
目录
一、Hooks(useContext)
二、Hooks(useReducer)
三、Hooks(useContext搭配useReducer使用)
四、自定义Hooks
一、Hooks(useContext) 二、接收一个context对象(React.createContext的返回值)目录
- 一、hooks(useContext)
- 二、hooks(useReducer)
- 三、hooks(useContext搭配useReducer使用)
- 四、自定义hooks
一、hooks(useContext)
接收一个 context 对象(React.createContext 的返回值)并返回该 context 的当前值。当前的 context 值由上层组件中距离当前组件最近的 <MyContext.Provider> 的 value prop 决定。
本文共计1073个文字,预计阅读时间需要5分钟。
目录
一、Hooks(useContext)
二、Hooks(useReducer)
三、Hooks(useContext搭配useReducer使用)
四、自定义Hooks
一、Hooks(useContext) 二、接收一个context对象(React.createContext的返回值)目录
- 一、hooks(useContext)
- 二、hooks(useReducer)
- 三、hooks(useContext搭配useReducer使用)
- 四、自定义hooks
一、hooks(useContext)
接收一个 context 对象(React.createContext 的返回值)并返回该 context 的当前值。当前的 context 值由上层组件中距离当前组件最近的 <MyContext.Provider> 的 value prop 决定。

