Diff
checker
テキスト
テキスト
画像
ドキュメント
Excel
フォルダ
Legal
Enterprise
デスクトップ
料金
ログイン
Diffchecker デスクトップのダウンロード
テキスト比較
2 つのテキスト ファイルの違いを見つける
ツール
履歴
ライブエディター
未変更行を折りたたむ
折り返しなし
レイアウト
分割
統合
比較精度
スマート
単語
文字
シンタックスハイライト
構文を選択
無視
テキスト変換
最初の差分へ移動
入力を編集
Diffchecker Desktop
Diffcheckerを実行する最も安全な方法。Diffchecker Desktopアプリを入手:あなたの差分はコンピューターから出ることはありません!
Desktopを入手
useFieldArray sandbox diff
作成日
4 年前
差分は期限切れになりません
クリア
エクスポート
共有
説明
2 削除
行
合計
削除
文字
合計
削除
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
144 行
すべてコピー
1 追加
行
合計
追加
文字
合計
追加
この機能を引き続き使用するには、アップグレードしてください
Diff
checker
Pro
価格を見る
144 行
すべてコピー
import React from "react";
import React from "react";
コピー
コピー済み
コピー
コピー済み
import { useForm, useFieldArray, Controller
, useWatch
} from "react-hook-form";
import { useForm, useFieldArray, Controller
} from "react-hook-form";
import ReactDOM from "react-dom";
import ReactDOM from "react-dom";
import "./styles.css";
import "./styles.css";
let renderCount = 0;
let renderCount = 0;
function App() {
function App() {
コピー
コピー済み
コピー
コピー済み
const { register, control, handleSubmit, reset
, watch
} = useForm({
const { register, control, handleSubmit, reset
} = useForm({
defaultValues: {
defaultValues: {
test: [{ firstName: "Bill", lastName: "Luo" }]
test: [{ firstName: "Bill", lastName: "Luo" }]
}
}
});
});
const {
const {
fields,
fields,
append,
append,
prepend,
prepend,
remove,
remove,
swap,
swap,
move,
move,
insert,
insert,
replace
replace
} = useFieldArray({
} = useFieldArray({
control,
control,
name: "test"
name: "test"
});
});
const onSubmit = (data) => console.log("data", data);
const onSubmit = (data) => console.log("data", data);
// if you want to control your fields with watch
// if you want to control your fields with watch
// const watchResult = watch("test");
// const watchResult = watch("test");
// console.log(watchResult);
// console.log(watchResult);
// The following is useWatch example
// The following is useWatch example
// console.log(useWatch({ name: "test", control }));
// console.log(useWatch({ name: "test", control }));
renderCount++;
renderCount++;
return (
return (
<form onSubmit={handleSubmit(onSubmit)}>
<form onSubmit={handleSubmit(onSubmit)}>
<h1>Field Array </h1>
<h1>Field Array </h1>
<p>The following demo allow you to delete, append, prepend items</p>
<p>The following demo allow you to delete, append, prepend items</p>
<span className="counter">Render Count: {renderCount}</span>
<span className="counter">Render Count: {renderCount}</span>
<ul>
<ul>
{fields.map((item, index) => {
{fields.map((item, index) => {
return (
return (
コピー
コピー済み
コピー
コピー済み
<li key={item
.id}>
<li key={item
?
.id}>
<input {...register(`test.${index}.firstName`)} />
<input {...register(`test.${index}.firstName`)} />
<Controller
<Controller
render={({ field }) => <input {...field} />}
render={({ field }) => <input {...field} />}
name={`test.${index}.lastName`}
name={`test.${index}.lastName`}
control={control}
control={control}
/>
/>
<button type="button" onClick={() => remove(index)}>
<button type="button" onClick={() => remove(index)}>
Delete
Delete
</button>
</button>
</li>
</li>
);
);
})}
})}
</ul>
</ul>
<section>
<section>
<button
<button
type="button"
type="button"
onClick={() => {
onClick={() => {
append({ firstName: "appendBill", lastName: "appendLuo" });
append({ firstName: "appendBill", lastName: "appendLuo" });
}}
}}
>
>
append
append
</button>
</button>
<button
<button
type="button"
type="button"
onClick={() =>
onClick={() =>
prepend({
prepend({
firstName: "prependFirstName",
firstName: "prependFirstName",
lastName: "prependLastName"
lastName: "prependLastName"
})
})
}
}
>
>
prepend
prepend
</button>
</button>
<button
<button
type="button"
type="button"
onClick={() =>
onClick={() =>
insert(parseInt(2, 10), {
insert(parseInt(2, 10), {
firstName: "insertFirstName",
firstName: "insertFirstName",
lastName: "insertLastName"
lastName: "insertLastName"
})
})
}
}
>
>
insert at
insert at
</button>
</button>
<button type="button" onClick={() => swap(1, 2)}>
<button type="button" onClick={() => swap(1, 2)}>
swap
swap
</button>
</button>
<button type="button" onClick={() => move(1, 2)}>
<button type="button" onClick={() => move(1, 2)}>
move
move
</button>
</button>
<button
<button
type="button"
type="button"
onClick={() =>
onClick={() =>
replace([
replace([
{
{
firstName: "test1",
firstName: "test1",
lastName: "test1"
lastName: "test1"
},
},
{
{
firstName: "test2",
firstName: "test2",
lastName: "test2"
lastName: "test2"
}
}
])
])
}
}
>
>
replace
replace
</button>
</button>
<button type="button" onClick={() => remove(1)}>
<button type="button" onClick={() => remove(1)}>
remove at
remove at
</button>
</button>
<button
<button
type="button"
type="button"
onClick={() =>
onClick={() =>
reset({
reset({
test: [{ firstName: "Bill", lastName: "Luo" }]
test: [{ firstName: "Bill", lastName: "Luo" }]
})
})
}
}
>
>
reset
reset
</button>
</button>
</section>
</section>
<input type="submit" />
<input type="submit" />
</form>
</form>
);
);
}
}
const rootElement = document.getElementById("root");
const rootElement = document.getElementById("root");
ReactDOM.render(<App />, rootElement);
ReactDOM.render(<App />, rootElement);
保存された差分
原文
ファイルを開く
import React from "react"; import { useForm, useFieldArray, Controller, useWatch } from "react-hook-form"; import ReactDOM from "react-dom"; import "./styles.css"; let renderCount = 0; function App() { const { register, control, handleSubmit, reset, watch } = useForm({ defaultValues: { test: [{ firstName: "Bill", lastName: "Luo" }] } }); const { fields, append, prepend, remove, swap, move, insert, replace } = useFieldArray({ control, name: "test" }); const onSubmit = (data) => console.log("data", data); // if you want to control your fields with watch // const watchResult = watch("test"); // console.log(watchResult); // The following is useWatch example // console.log(useWatch({ name: "test", control })); renderCount++; return ( <form onSubmit={handleSubmit(onSubmit)}> <h1>Field Array </h1> <p>The following demo allow you to delete, append, prepend items</p> <span className="counter">Render Count: {renderCount}</span> <ul> {fields.map((item, index) => { return ( <li key={item.id}> <input {...register(`test.${index}.firstName`)} /> <Controller render={({ field }) => <input {...field} />} name={`test.${index}.lastName`} control={control} /> <button type="button" onClick={() => remove(index)}> Delete </button> </li> ); })} </ul> <section> <button type="button" onClick={() => { append({ firstName: "appendBill", lastName: "appendLuo" }); }} > append </button> <button type="button" onClick={() => prepend({ firstName: "prependFirstName", lastName: "prependLastName" }) } > prepend </button> <button type="button" onClick={() => insert(parseInt(2, 10), { firstName: "insertFirstName", lastName: "insertLastName" }) } > insert at </button> <button type="button" onClick={() => swap(1, 2)}> swap </button> <button type="button" onClick={() => move(1, 2)}> move </button> <button type="button" onClick={() => replace([ { firstName: "test1", lastName: "test1" }, { firstName: "test2", lastName: "test2" } ]) } > replace </button> <button type="button" onClick={() => remove(1)}> remove at </button> <button type="button" onClick={() => reset({ test: [{ firstName: "Bill", lastName: "Luo" }] }) } > reset </button> </section> <input type="submit" /> </form> ); } const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement);
変更されたテキスト
ファイルを開く
import React from "react"; import { useForm, useFieldArray, Controller } from "react-hook-form"; import ReactDOM from "react-dom"; import "./styles.css"; let renderCount = 0; function App() { const { register, control, handleSubmit, reset } = useForm({ defaultValues: { test: [{ firstName: "Bill", lastName: "Luo" }] } }); const { fields, append, prepend, remove, swap, move, insert, replace } = useFieldArray({ control, name: "test" }); const onSubmit = (data) => console.log("data", data); // if you want to control your fields with watch // const watchResult = watch("test"); // console.log(watchResult); // The following is useWatch example // console.log(useWatch({ name: "test", control })); renderCount++; return ( <form onSubmit={handleSubmit(onSubmit)}> <h1>Field Array </h1> <p>The following demo allow you to delete, append, prepend items</p> <span className="counter">Render Count: {renderCount}</span> <ul> {fields.map((item, index) => { return ( <li key={item?.id}> <input {...register(`test.${index}.firstName`)} /> <Controller render={({ field }) => <input {...field} />} name={`test.${index}.lastName`} control={control} /> <button type="button" onClick={() => remove(index)}> Delete </button> </li> ); })} </ul> <section> <button type="button" onClick={() => { append({ firstName: "appendBill", lastName: "appendLuo" }); }} > append </button> <button type="button" onClick={() => prepend({ firstName: "prependFirstName", lastName: "prependLastName" }) } > prepend </button> <button type="button" onClick={() => insert(parseInt(2, 10), { firstName: "insertFirstName", lastName: "insertLastName" }) } > insert at </button> <button type="button" onClick={() => swap(1, 2)}> swap </button> <button type="button" onClick={() => move(1, 2)}> move </button> <button type="button" onClick={() => replace([ { firstName: "test1", lastName: "test1" }, { firstName: "test2", lastName: "test2" } ]) } > replace </button> <button type="button" onClick={() => remove(1)}> remove at </button> <button type="button" onClick={() => reset({ test: [{ firstName: "Bill", lastName: "Luo" }] }) } > reset </button> </section> <input type="submit" /> </form> ); } const rootElement = document.getElementById("root"); ReactDOM.render(<App />, rootElement);
違いを見つける