How to get the data from React Context Consumer outside the render

后端 未结 5 540
情深已故
情深已故 2020-12-15 18:03

I am using the new React Context API and I need to get the Consumer data from the Context.Consumer variable and not using it inside the render method. Is there anyway that I

5条回答
  •  温柔的废话
    2020-12-15 18:21

    You can via an unsupported getter:

    YourContext._currentValue
    

    Note that it only works during render, not in an async function or other lifecycle events.

提交回复
热议问题