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 }} />
</>
);
When using the
FlatfileButtoncomponent, changing the props is not reflected in changed behaviour.Example:
If
barchanges we expected the use of theFlatfileButtonto use the latestsettingsprovided 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, theuseEffecthook is never invalidated because it has an empty dependency array[]which means theFlatfileImporterinstance will never change after the initial render.react-adapter/src/components/FlatFileButton.tsx
Line 64 in 625e9fe
Our workaround was to set the
keybased on ourbarstate which causes the component instance to get garbage collected by React's render pass.