问题描述
提前致谢。
解决方法
如果需要从应用的任何屏幕全局更新 UI,那么我们可以实现全局状态管理。
有两种简单的方法来实现全局状态,当对它进行更改时更新 UI。
- React Redux
- 反应上下文 API
使用其中之一并在全局状态中进行更改,并将值分配给需要更改 UI 的 UI 组件。
您只需调用 API 并更新全局状态即可更新徽章计数。
查看官方文档以实现全局状态:
-
对于 React Redux:https://react-redux.js.org/
-
对于上下文 API:https://reactjs.org/docs/context.html