小编Doo*_*omd的帖子

如何使用 react-hook-form 在 React 中存储无线电组的状态

我正在使用react-hook-form存储表单数据,这些数据根据Codesandbox.io 上看到的代码分为两页。我能够使用defaultValue={state.data.firstName}例如属性分配成功地存储简单的文本输入(如名字、电子邮件等)...但我无法弄清楚如何使用 react 建议的模型将选中的项目存储在无线电组中-钩形。我检查了他们的文档,遗憾的是很少提到单选按钮组状态存储。这可以使用他们的 API 吗?

import React from "react";
import { useForm } from "react-hook-form";
import { withRouter } from "react-router-dom";
import { useStateMachine } from "little-state-machine";
import updateAction from "./updateAction";

const Step1 = props => {
  const { register, handleSubmit, errors } = useForm();
  const { action, state } = useStateMachine(updateAction);
  const onSubit = data => {
    action(data);
    props.history.push("./step2");
  };

  return (
    <form onSubmit={handleSubmit(onSubit)}>
      <h2>Step 1</h2>
      <label>
        First Name:
        <input …
Run Code Online (Sandbox Code Playgroud)

javascript reactjs react-hook-form

11
推荐指数
1
解决办法
1万
查看次数

Flutter:接收数据时连接关闭

我正在调用 post API,有时我从服务器得到响应,有时我收到异常Connection closed while receiving data。两种情况下的请求都相同,并且根据后端服务器日志,发送了响应,但我没有收到。我在模拟器和实际设备中都有这个问题。

try {
  final result =
      await http.post(url, body: encodedBody, headers: apiHeader);
  Map<String, dynamic> response = json.decode(result.body);

  print("Response: $response");

  return response;
} catch (error) {
  Map<String, dynamic> response = Map<String, dynamic>();
  response['success'] = false;
  response['message'] = error;
  return response;
}
Run Code Online (Sandbox Code Playgroud)

api http httpexception dart flutter

8
推荐指数
1
解决办法
5594
查看次数

如何使用 Svelte 在双击时制作 &lt;div&gt; contentEditable?

我是Svelte ( 3.0+ ) 的新手……对于我的最新项目,我想模拟许多“待办事项”列表的功能,允许您通过双击它们来编辑以前提交的待办事项(这是我正在寻找的功能示例)。

我想,第一步是弄清楚如何contentEditable使用 Svelte 和on:dblclick事件处理程序制作 div 。我无法弄清楚此任务的语法(尽管我可以使用vanilla javascript 来完成)。

这是我到目前为止的 Svelte 代码:(这是在CodeSandBox.io 上- 请参阅页面:CEDiv.svelte)

<script>
function edit(event) {
    //update db functionality goes here
    //alert("you've 'submitted' your edit")
}

function handleDblClick() {
    //I need help HERE...and probably on the div on:dblclick down below....
}
function handleKeydown() {
    key = event.key;
    keyCode = event.keyCode;
    //submit the div's content to the edit function if enter or tab is pressed. …
Run Code Online (Sandbox Code Playgroud)

html javascript css svelte svelte-3

4
推荐指数
1
解决办法
1354
查看次数

使用Regex和PHP从String中删除括号中的文本

我正在尝试编写一个简单的php函数,它将删除字符串中两个括号之间的所有内容.

以下是典型字符串的外观:

[img_assist|nid=332|title=|desc=|link=none|align=left|width=70|height=61] On November 14, Katherine Grove participated in Tulane University's School of Architecture Continuing Education Conference . She presented the firm's work in a presentation titled "Cradle to Cradle Design for the Built Environment".The Tulane School of Architecture Continuing Education Conference is designed to make continuing education credits available to Tulane School of Architecture alumni and the local architecture community, with a focus on sustainable design. Kathy currently directs the firm’s pro-bono involvement with the nonprofit Make It …

php regex string

1
推荐指数
1
解决办法
1432
查看次数