如何清除页面更改中表单错误的Redux状态

时间:2020-04-10 21:14:57

标签: reactjs redux

我有一个存储错误的redux存储。对于我的登录和注册表单,共享错误;如果我切换表单,则错误仍然存​​在。现在我知道我可以做类似

React.useEffect(() => {
  props.clearErrors();
}
...

const mapActionsToProps = (dispatch) => {
  return {
     ...,
     clearErrors: () => {
       dispatch({ type: 'CLEAR_ERRORS' });
     },
  }
};

但是,我想清除每次页面更改时的错误。

1 个答案:

答案 0 :(得分:0)

要清除页面更改错误,您应该通过import Cocoa import SwiftUI @NSApplicationMain class AppDelegate: NSObject, NSApplicationDelegate { var window: NSWindow! func applicationDidFinishLaunching(_ aNotification: Notification) { let contentView = ContentView() window = NSWindow( contentRect: NSRect(x: 0, y: 0, width: 480, height: 300), styleMask: [.titled, .closable, .miniaturizable, .resizable, .fullSizeContentView], backing: .buffered, defer: false) window.center() window.setFrameAutosaveName("Main Window") window.contentView = NSHostingView(rootView: contentView window.makeKeyAndOrderFront(nil) } func applicationWillTerminate(_ aNotification: Notification) { // Insert code here to tear down your application } func applicationDockMenu(_ sender: NSApplication) -> NSMenu? { let menu = NSMenu() let reOpenMenuItem = NSMenuItem(title:"Re-Open", action:#selector(AppDelegate.reOpen), keyEquivalent:"") menu.addItem(reOpenMenuItem) return menu } @objc func reOpen(sender : NSMenuItem) { print("XXX") } } 并在returning a function中添加一些逻辑来调度页面卸载操作:

useEffect