- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
We are storing the data for the particular component in the redux store by using creatStore() and where combining all the component's state by using combineReducers().Now Once we came out of the page we need to clear the state stored using redux. This is not the dublicate question as written in How should I clear state in componentWillUnmount? because in this question they want to clear the state of the page that they save by using this.state{}.In our scenario we have to clean from global state (redux-stored-state) for the particular component.We want a global solution so that we can apply to all our component.Please assist me.
最佳答案
您可以在 componentWillUnmount
中分派(dispatch)一个 reset
操作,该操作将由相应的 reducer 处理。 reducer 将清除 redux 状态。
为了使其全局化,您可以创建一个高阶组件,将重置操作的分派(dispatch)添加到它所应用到的组件。您可以为整个应用程序使用一个 reducer 来处理重置操作。
关于reactjs - 如何清除componentWillUnmount中组件存储的redux状态?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43510651/
我在类组件中有以下代码,我正在尝试测试 componentWillUnmount。 export class Hello extends React.PureComponent { constru
App.js import React from "react"; import CounterOne from "./CounterOne"; function App() { const [d
我正在使用出色的 create-react-app 工具来构建应用程序。我的问题正如标题所暗示的那样微不足道,但我无法解决。我已经在 github 上发布了一个简单的应用程序来说明: https://
我已经构建了一个表单,其中有一个下拉菜单,将显示下面字段的选择。也就是说,首先选择了 optionSet1,其中显示了 3 个字段。如果用户更改下拉列表以选择 optionSet2,则会显示不同的选项
我一直遇到这样的问题:刷新当前页面(以及随后的组件)时,componentDidMount() 方法中的代码无法正确触发。但是,只需通过单击链接在我的网站中导航和路由,它就可以完美地工作。刷新当前页面
我有一个倒计时计时器,一旦它变为 0,它应该调用一个方法。然后,呈现一个新页面,倒计时应该重置并重新开始。它按预期工作,直到组件卸载。然后每秒调用方法 timeNext(),因为间隔不再停止。 imp
我有一个主干应用程序,我试图在其中集成 React 组件。 React 组件使用以下代码安装: ReactDOM.render( , node );其中 node 是 DOM 模式。这样 React
我正在做这个简单的步骤,但 unmount 没有打电话,我不知道为什么。请我需要一个解决方案,我需要卸载才能在导航到另一个屏幕时被调用... class Homemain extends Compon
我试图了解 componentWillUnmount 在 ReactJS 中的工作原理。它是自动调用的还是我们需要手动调用 unmountComponentAtNode 才能使其工作? 我正在使用带有
我正在reactjs-flux上编写一个简单的应用程序,一切正常,除了我收到reactjs的警告,告诉我我正在对未安装的组件调用setState。 我发现这是因为组件所 Hook 的变更监听器没有从
我认为标题已经说明了一切。每次卸载仍在获取的组件时,都会显示黄色警告。安慰 Warning: Can't call setState (or forceUpdate) on an unmounted
我在窗口中添加了一个监听器来检测 onClickOutside 类型的场景(具体来说,当在菜单外单击时折叠菜单)。这是带有相关代码的组件: import React, { Component, Pro
我有一个带有 redux-form 的表单设置,基本上想创建一个场景,如果在任何表单的输入中填充了内容,并且您尝试离开页面,您会收到提示。 目的是在他们单击取消 时取消页面卸载或页面导航。我尝试创建一
有人可以让我知道我在 componentWillUnmount 我的代码中缺少什么吗。 错误是 Warning: Can't perform a React state update on an un
我在 componentDidMount 中的应用程序中执行服务器请求。所以我在 componentDidMount 中调用 setState。我需要卸载吗componentWillUnmount 中
我正在使用静态方法来实现我的监听器功能。示例: class MyComponent extends Component { static heavyCalculation() { console.
根据docs , ComponentWillUnmount 能够取消请求。 我有一个页面请求加载 iframe,以及其他页面请求。如果用户决定在页面仍在处理请求时离开该页面,我该如何取消这些请求,以免
我有一个正在运行的加载组件,它在加载 8 秒后取消。这段代码有效,但对我来说感觉不对,我想知道是否有更好的方法来做到这一点。 没有设置 this.mounted 我得到错误: Warning: Can
我正在制作一个小倒数计时器作为 React 练习(为我自己,而不是类或其他任何东西)并且一切正常(尽管笔记总是受欢迎的)除了我注意到即使在组件完成后它也会继续倒计时卸载。 所以现在我想让它在卸载时停止
我设置如下代码。 componentWillUnmount() { this.setState({'modal':false}) or this.setState({}) } 但状态不清楚。我
我是一名优秀的程序员,十分优秀!