Skip to content

Prop (settings) changes do not reflect in behavior changes #22

Description

@beaucollins

When using the FlatfileButton component, changing the props is not reflected in changed behaviour.

Example:

cons Foo = () => {
  const [bar, setBar] = React.useState('');

  return (
    <>
      <input value={bar} onChange={(e) => setBar(e.target.value)} />
      <FlatfileButton settings={{ bar }} />
    </>
  );
}

If bar changes we expected the use of the FlatfileButton to use the latest settings provided to it via its props. However it only ever uses the settings with the initial state value of "" (empty string).

Looking at the implementation of FlatfileButton, the useEffect hook is never invalidated because it has an empty dependency array [] which means the FlatfileImporter instance will never change after the initial render.

const tempImporter = new FlatfileImporter(licenseKey, settings, customer);

Our workaround was to set the key based on our bar state which causes the component instance to get garbage collected by React's render pass.

  return (
    <>
      <input value={bar} onChange={(e) => setBar(e.target.value)} />
      <FlatfileButton key={bar} settings={{ bar }} />
    </>
  );

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingfeature requestrequested feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions