Skip to content

[2020-03-07]React的Context #44

@pdji1602003

Description

@pdji1602003

ReactuseContext的使用流程:

  1. 使用React.createContext()建立一個context物件,比如RecipeContext
  2. <RecipeContext.Provider></RecipeContext.Provider>接受一個prop為value
  3. Value的值就是需要傳遞的值
  4. 有個很棒的做法是把需要傳遞的值儲存在變數內
  5. 記得把我們的context物件輸出,以在其他components做使用
  6. 使用useContext來使用我們的context物件,使用destruture把需要的function抽離出來
  7. 接下來就可以進一步使用我們透過context進行傳遞的物件囉!

Metadata

Metadata

Assignees

No one assigned

    Labels

    ReactEverything about React

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions