linkstate icon indicating copy to clipboard operation
linkstate copied to clipboard

Is it possible to link multiple states?

Open divyenduz opened this issue 7 years ago • 1 comments

Is it possible to link a change event to multiple objects in state?

In my use case, there are three state objects that have 3 inputs in my app but a special case requires me to keep them in sync against one input object.

P.S. Thanks for building this.

divyenduz avatar Feb 28 '18 10:02 divyenduz

Currently, I am doing something as ugly as

onTitleChange={
                  type === "CAREER"
                    ? e => {
                        e.persist();
                        this.setState(prevState => {
                          return {
                            ...prevState,
                            version: {
                              ...prevState.version,
                              title_de: e.target.value,
                              title_en: e.target.value,
                              title_cn: e.target.value
                            }
                          };
                        });
                      }
                    : linkState(this, "version.title_de")
                }

but I wonder if this can be made better by composed linkState or something.

I can pick up the task to make statePath an array (optionally) or string and sync multiple states in case it is an array but of course, it has to be a common use case for it to be incorporated in the library.

divyenduz avatar Feb 28 '18 11:02 divyenduz