1

In suite of React apps we're placing per view set of reusable apollo-backed form components with just one save button placed outside of the form components. On a save button clicked each component (with dirty state) should execute the mutation to persist changes.

I wonder about possible implementation options and I would like to avoid using refs.

The problem to be solved seems to be - how to call a method outside of the component - I tried to follow on this question Call child method from parent and while I'd rather do not use any React way of communication between components, one particular answer that looks promising to me is https://stackoverflow.com/a/45582558/3021889 - still I'd like to hear what options do I have.

ciekawy
  • 2,238
  • 22
  • 35
  • On the surface this seems to break the state pattern for react. You don't want to make it dirty or mutate it, but create a new copy of state when you save. But to your specific question of communication between components, if you don't do it the react way, you are going to put effort into working around the way it is intended to work... sort of futile. If you want an easier way to persist your changes and communicate between components, I suggest looking at Redux. From there you have a clean way to handle communication via a central store. – J E Carter II Nov 28 '18 at 17:15

0 Answers0