Skip to content

React component does not re-render when error is added manually. #1

@erichaus

Description

@erichaus

First, thanks for providing this react version of the excellent changeset lib!

I was able to get it working except one issue which is when I want to manually add an error to the changeset as part of a try/catch handler.

When I add the error the component does not recognize the change and thus does not rerender, but if I manually trigger a rerender via e.g. hacked useReducer() trick, the component will update and show the error.

    if (changeset.isValid) {
      await changeset.save();

      try {
        await submit(changeset.data);
      } catch (err) {
        await catchErrors(err, changeset);
        // force rerender. 
        // update(); <-- without this hacked forced update the error that's added in catchErrors() will not trigger a re-render of the component.
      }
    }
export function catchErrors(errors, changeset) {
  if (errors.message) {
    changeset.addError('nonFieldErrors', {
      value: 'nonFieldErrors',
      validation: [errors.message],
    });
  }
}

Is there a better way to tell React to rerender when an error is added to the changeset?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions