Skip to content

Commit

Permalink
feat: form updates on schema change in the code editor
Browse files Browse the repository at this point in the history
  • Loading branch information
keyurparalkar committed Apr 15, 2024
1 parent ea65a3e commit 8033f6b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
12 changes: 6 additions & 6 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ const FormValues = schema.fields.reduce((acc, currValue) => {
export type TFormValues = typeof FormValues;

function App() {
const [value, setValue] = useState(`${JSON.stringify(schema, null, 2)}`);
const onChange = useCallback((val, viewUpdate) => {
console.log("val:", val);
setValue(val);
const [value, setValue] = useState(schema);
const onChange = useCallback((val) => {
const tempSchema = SchemaDef.parse(JSON.parse(val));
setValue(tempSchema);
}, []);

const {
Expand All @@ -43,7 +43,7 @@ function App() {
<div id="editor">
<CodeMirror
className="border border-slate-300"
value={value}
value={`${JSON.stringify(value, null, 2)}`}
height="500px"
extensions={[json()]}
onChange={onChange}
Expand All @@ -52,7 +52,7 @@ function App() {
<div id="form-container" className="border border-slate-300">
<form className="my-5 mx-10" onSubmit={handleSubmit(onSubmit)}>
<SchemaRenderer
schema={schema}
schema={value}
errors={errors}
register={register}
/>
Expand Down
2 changes: 1 addition & 1 deletion src/components/fields/InputField.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const InputField = (props: InputFieldProps) => {
console.log({ htmlFor, validation });
return (
<>
<div className="flex flex-col space-y-2">
<div className="flex flex-col space-y-2 my-2">
<Label htmlFor={htmlFor}>{labelText}</Label>
<Input
id="htmlFor"
Expand Down

0 comments on commit 8033f6b

Please sign in to comment.