如何使 HTML 选择标签与 Remix Form 一起使用?
我一直在探索 Remix,并且非常喜欢从 Remix 导出表单的工作原理。但是,我似乎无法使选择与表单一起使用。使用 ref 提交表单可以完成这项工作,但会重新加载页面,这是我不想要的。有什么解决方法吗?
I've been exploring Remix and quite like how the Form export from Remix works. However, i can't seem to make select work with Form. Using ref to submit form does the job but reloads the page which is something I don't want. Is there any workaround for this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
提交混音表单的最简单方法是使用提交按钮。我假设在这种情况下您不需要提交按钮而是在选择时提交?
确保您使用的是实际的 Remix Form 组件。 HTML 表单元素始终会触发整页重新加载。
如果您的错误仍然存在,那么我假设您的 ref 触发了
form
HTML 元素的默认行为,这就是提交表单会触发整个页面重新加载的原因。要以编程方式提交 Remix 表单,您可以使用useFetcher
挂钩。您可以在此处找到useFetcher
文档。您的代码将如下所示:
The easiest way to submit a Remix Form is by using a submit button. I assume in this case you don't want a submit button but rather submit on select?
Make sure that you are using the actual Remix Form component. The HTML form element will always trigger a full page reload.
If your error persists, then I assume that your ref triggers the default behavior of the
form
HTML element and that's why submitting the form triggers a full page reload. To programmatically submit a Remix form, you can use theuseFetcher
hook. You can find theuseFetcher
documentation here.Your code will looking something like this:
看起来 Remix 团队添加了一个新的钩子 (useSubmit) 来处理命令式表单提交,就像我的例子一样。
阅读更多: https://reactrouter.com/en/main/hooks/use-submit
Looks like the Remix team have added a new hook (useSubmit) to handle imperative form submissions like in my case.
Read More: https://reactrouter.com/en/main/hooks/use-submit