eclipsesource / jsonforms

Customizable JSON Schema-based forms with React, Angular and Vue support out of the box.
http://jsonforms.io
Other
2.2k stars 371 forks source link

Unpredictable data change #2260

Open jankvapil opened 9 months ago

jankvapil commented 9 months ago

Describe the bug

When I quickly click a button, sometimes the previous state is logged to the console. I can never be sure that I'm accessing actual form data (or at least I don't know how to get to them since there is no real reference to them or to the form)

const initialData = {
  name: 'Max Power',
};

const ClearFormExample = () => {
  const [data, setData] = useState(initialData);

  return (
    <div>
      <JsonForms
        schema={schema}
        uischema={uischema}
        data={data}
        renderers={materialRenderers}
        cells={materialCells}
        onChange={({ data, _errors }) => setData(data)}
      />
      <Button onClick={() => console.log(data)} color='primary'>
        Print data
      </Button>
    </div>
  );
};

Expected behavior

It would be nice to be able to directly access the internal state of the form by reference

Steps to reproduce the issue

  1. Just try the modified example from the docs

Screenshots

No response

Which Version of JSON Forms are you using?

v3.1.0

Framework

React

RendererSet

No response

Additional context

No response

sdirix commented 9 months ago

Hi @jankvapil,

In the React Material renderers we have two debounce mechanisms:

You are likely hitting the first debounce. If you type fast and then click on a button. Obviously that's not great.

There are multiple improvements which can be done:

Would you be interested in contributing one or more of these improvements?