Last active
March 19, 2022 11:41
-
-
Save Codennnn/2df3bfc97883390e0b29acc07708ea21 to your computer and use it in GitHub Desktop.
react context 的数据状态管理
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { createContext, useContext, useEffect, useState } from 'react'; | |
const XxxContext = createContext({}); | |
export function XxxContextProvider(props: { children: React.ReactNode }) { | |
const [state, setState] = useState(); | |
const value = { state, setState }; | |
return <XxxContext.Provider value={value}>{props.children}</XxxContext.Provider>; | |
} | |
export function useXxxContext() { | |
const context = useContext(XxxContext); | |
return context; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment