-
Notifications
You must be signed in to change notification settings - Fork 0
[2020-03-07]React的Context #44
Copy link
Copy link
Open
Labels
ReactEverything about ReactEverything about React
Description
ReactuseContext的使用流程:
- 使用React.createContext()建立一個context物件,比如RecipeContext
- <RecipeContext.Provider></RecipeContext.Provider>接受一個prop為value
- Value的值就是需要傳遞的值
- 有個很棒的做法是把需要傳遞的值儲存在變數內
- 記得把我們的context物件輸出,以在其他components做使用
- 使用useContext來使用我們的context物件,使用destruture把需要的function抽離出來
- 接下來就可以進一步使用我們透過context進行傳遞的物件囉!
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
ReactEverything about ReactEverything about React