Skip to content
This repository has been archived by the owner on Jun 5, 2023. It is now read-only.

Latest commit

 

History

History
42 lines (36 loc) · 1.08 KB

README.md

File metadata and controls

42 lines (36 loc) · 1.08 KB

React 嵌套表单

常用例子

import { Form, useFieldReader, useFieldTrigger } from "@idler8/form-react";
const Input = ({ value = "", onChange }) => (
  <input value={value} onChange={(e) => onChange?.(e.target.value)} />
);
const Field = ({ name }) => {
  const value = useFieldReader(name);
  const onChange = useFieldTrigger(name);
  return <Input value={value} onChange={onChange} />;
};
const Fields = () => {
  const value = useFieldReader();
  const onChange = useFieldTrigger();
  useEffect(() => {
    onChange({ formKey: { fieldKey: 2 } });
  }, []);
  return (
    <div>
      <div>{JSON.stringify(value)}</div>
      <Field name={["formKey", "fieldKey"]} />
    </div>
  );
};

ReactDOM.createRoot(document.getElelemtByID("root")).render(
  <Form>
    <Fields />
  </Form>
);

更多用法可以参考测试用例

或者发起ISSUE提出问题